Selecting Text In A Word Table Cell
This has probably been answered many times before but I can't find the solution. I need to insert some text into a Word table and then change the font without affecting the text that was already in the cell. My code will look something like this:
Code: Set oWord = CreateObject("Word.Application") ' Create a new Word document based on works_oder.dot template oWord.application.Documents.Add App.Path & " emplatesworks_order.dot" oWord.Visible = True oWord.Activate
With oWord.ActiveDocument.tables(1) ' First table in Word template .cell(1, 2).range.insertafter "Temp 0001" .cell(2, 1).range.insertafter " " & cmbCustomers .cell(2, 2).range.insertafter vbCrLf & txtDrawingNo .cell(2, 4).range.insertafter vbCrLf & txtWorksOrderNo .cell(3, 1).range.insertafter " " & txtCustOrderNo .cell(4, 1).range.insertafter vbCrLf & txtRequiredBy .cell(4, 2).range.insertafter vbCrLf & txtDescription End With
I guess I need to select the text I've just added and then apply the font formatting I need, but I can't quite work out the syntax to select just the new text and exclude the original contents of the cell. Thanks!
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Selecting A Whole Cell In A Word Table
Hi there.
I'm struggeling with the following:
I have a Word document with 2 columns. It contains 100 rows, which gives a total of 200 cells.
One of the rows are looking something like this:
_______________________________
|________________|______________|
In my code, I'm able to locate/find the correct row I want to do my selection.
I have a bookmark (called "Labelx" where x is the number of the cell) in every cell.
I'm able to select the first cell (that is the cell to the left), and I'm also able to put my cursor in the next cell (the one to the right).
The big challenge is to "mark"/highlight/select the cell to the right.
The purpose is that I want to select this cell and delete all the contents in it.
Can anyone give me some direction?
So far I have this code:
BookM = "Label" & (i+2) 'This selects the bookmark in the row below the row I want to delete
ActiveDocument.Bookmarks(BookM).Range.Select
Selection.MoveUp Unit:wdLine, Count:=1
Selection.EndKey Unit:=wdStory, Extend:= wdExtend
Selection.Delete
This code, selects all the remaining rows in the documents and deletes them. This is my purpose.
But I also want the code to delete the cell to the right in the last row AFTER deleting the remaining rows.
Hope that my explaination is good enough, if not - give me a hint and I will try to improve.....
Changing Text Orientation/Direction In Table Cell - VBA Word Automation
Hi,
I need to change the text direction/orientation to 90 degrees in a table cell in a Word document using automation. I know how to achieve this manually.
Right click on a table cell, select Text direction, in the window: select the orientation you want.
The same result I need to achieve through VBA automation. I am using Word 2003 & VB 6.
Could you please help me out in this regard ?
Thanks in advance.
Sisheer
Selecting Part Of Cell In Word
Hello,
in my application i send a pricelist to word.
It's placed in a table.
Now i want to select a part of the first cell in the row and set it bold.
Is this possible and how would you do it.
For example:
new
vbcr
article1
I want to put "new" in bold.
???
Word 97: How To Insert A Table Into An Existing Table Cell
Does anyone know how I can insert a New Table into a cell of another table?
In Word 2000, I can issue the following code when I am within a cell of a table and the table gets inserted correctly:
Dim rRange As Range, myTable As Table
With Selection
Set rRange = .Range
Set myTable = rRange.Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=4)
End With
However, in Word97, I am not able to do this. I get an error telling me that a table already exists. Has anyone had any success with being able to insert a new table into a cell of an existing table without doing a lot of cell/row inserts and cell merges?
How To Insert Table Into A Cell Of Another Table Using Word Object
hi friends,
i have inserted a table into word do using word object through VB
wddoc.tables.add selection.range, 2, 4
now i wanto to insert a table into the cell of the table created.
can u help me how to do that
i have tried like this
wddoc.tables(1).cell(1,1).range.tables.add selection.range,2,4
but i am getting an error saying that table already exists in that location,
PLEASE HELP ME OUT!!!!!
thanx
How To Insert Table Into A Table Cell Of Word
hi friends,
i am creating a word doc from VB and then i want to insert tables into it. i am inserting table in the following manner
wdapp.ActiveDocument.Tables.Add selection.range, 4, 1
wdapp.ActiveDocument.Tables.Add selection.range, 2, 2
but it is able to create the first table but not the second table. it is giving a error message saying that table already present in the location.
can u tell me how to insert 2 or more tables into the word doc through coding
thanx,
How To Insert Table Into A Table Cell Of Word
hi friends
i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.
wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range, 2, 1
thanx,
How To Insert Table Into A Table Cell Of Word
hi friends
i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.
set drange=wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range
wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add drange, 2, 1
i am using word 8.0 dll i.e word 97
thanx,
------------------------------------------------
Good Friend...
------------------------------------------------
Selecting Text In A Datagrid Cell
I have a datagrid with (suprise) so data in it. Currently when I single click a cell to begin editing it the entire contents of the cell become highlighted. Is there any way to move the select point to the end of that cell's contents by default when I enter the cell to edit it?
Thanks in advance. =)
Selecting A Specific Word Table?
I need to be able to access a table in word using vb6. I know how to access data in a table by using the Table(1) feature, but i need to be able to access the table without knowing where it exists in the document prior to running my tool. For example, the table i need may be the first table in the doc one time and then be the third table the next time. So i thought maybe i could trigger off of the caption somehow. Any ideas? below is how i am currently doing it.
If curTable = 1 Then
Count = 1
endOfTable = False
curTableString = "TableOne"
Set tblOneData = New Tables
While Not endOfTable
UpdateActivityBar ProgressBarActivity.ActiveBar, 0.1
Count = Count + 1
If Not endOfTable Then
endOfTable = wrdDoc.Tables(curTable).Rows(Count).IsLast
End If
Wend
.
.
and so on.
How To Get The Aligment Of A Table Cell In Word
Hi,
I have written a macro, which traverses the table of a word document and outputs the text in particular format to a text file. While doing so i need to retain the look of the table and for which i need to know the aligment of the cells in the table whether centered, left or right aligned.
Is there any means by which this be achieved?
Thanks
Niranjan
Getting Cell Alignment Of A Table In Word
Hi,
I have written a macro, which traverses the table of a word document and outputs the text in particular format to a text file. While doing so i need to retain the look of the table and for which i need to know the aligment of the cells in the table whether centered, left or right aligned.
Is there any means by which this be achieved?
Thanks
Niranjan
Copy A Cell To A Word Table
This type of topic has been going around a lot lately. I have been searching the forum, but am still lost on the subject. I have taught myself VBA in Excel and feel very comfortable with that. However, I know need to copy a cell(s) to a word table and am having a great deal of trouble with this. Can't seem to get it through my thick skull I guess. BTW have done a google search as well. Anyway, here is the story...
I have a sales worksheet that is filed out when an admin person answers the phone. The worksheet contains basic information...name address reason for call and the like. If the sale goes through I need the name and address copied into word for the contract (a lot double typing that can be typed once...push a button and presto; all of the fields in word are copied over). Anyway, if someone could spell this out for me, it would be a huge help. Thanks for the help in advance.
-JD
Colspan Of Table Cell In MS Word
Hi,
I'm wondering how my Macro can determine if a table cell in MS Word spans multiple columns and if so how many.
thanks in advance
MS WORD XP Table Cell Sizes
Hey there
I'm writing an application that reads data from a mutlidimensional array into tables in a word document. I've got it up and running with MS Word 2000, but with MS Word XP, some of the cell sizes on the tables are wrong.
anyone else run into something like this ?!?
oh btw. its not really VBA its in VB (using WORD10 library).
thanks in advance.
Word Creation - Table Cell Alignment
Hello everybody,
I am trying to create an MS word document automatically through VB. In that document, there should be a table. The table should have 4 columns. The data in the last two columns needs to be right aligned. I could create table and fill it with data from table. But I am not able to right align contents of 3rd and 4th columns of the table. Could anybody please help me ?
I am attaching the code I wrote(A part of it I got from net)
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oTitle As Object
Dim iCount As Integer
Dim intYCount As Integer
Dim intXCount As Integer
Dim bCreateOrGot As Boolean
Dim intXMax As Integer
Dim intYMax As Integer
Dim strTitle As String
strTitle = "My word document"
Dim rstTable As ADODB.Recordset
Dim qryTable As String
qryTable = "SELECT artisteid,productionname, grossamount, (grossamount*17.5/100) as vat FROM artistevouchers"
Set rstTable = New ADODB.Recordset
rstTable.Open qryTable, cnnArtists, adOpenDynamic
intYMax = rstTable.Fields.Count
rstTable.MoveLast
intXMax = rstTable.RecordCount + 1
rstTable.MoveFirst
On Error Resume Next ' Defer error trapping.
bCreateOrGot = True
Set oWord = New Word.Application
bCreateOrGot = False
err.Clear ' Clear Err object in case error occurred.
If bCreateOrGot = False Then
With oWord
.Visible = True
.Documents.Add ("c:project
eceipt.doc")
End With
End If
Set oDoc = oWord.ActiveDocument
On Error GoTo 0
If bCreateOrGot = True Then
With oDoc.Application.Selection
.InsertBefore Text:=strTitle & vbCrLf
With .Find
.Text = "^l"
With .Replacement
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
With .Font
.Bold = True
.Name = "Arial"
.Size = 8
End With
.MoveRight Unit:=wdCharacter, Count:=1
.InsertAfter Text:=vbCrLf
End With
Set oTable = oDoc.Tables.Add(Range:=Selection.Range, NUMROWS:=intXMax, NumColumns:=intYMax)
Else
With oDoc.Application.Selection
.InsertBefore Text:=vbCrLf & strTitle
Dim iloop As Integer
With .Find
.Text = "^l"
With .Replacement
.Text = ""
End With
.Execute Replace:=wdReplaceAll
End With
With .Font
.Bold = True
.Name = "Arial"
.Size = 8
End With
.MoveRight Unit:=wdCharacter, Count:=1
End With
Set oTable = oDoc.Tables.Add(Range:=oDoc.Range(Start:=17, End:=17), NUMROWS:=intXMax + 1, NumColumns:=intYMax)
End If
For intYCount = 0 To intYMax - 1 'Add headings
With oTable.Cell(Row:=1, Column:=intYCount + 1).Range
.InsertAfter Text:=rstTable.Fields(intYCount).Name
End With
Next
intXCount = 2
Dim f_total_gross_amount As Currency
Dim f_total_vat As Currency
f_total_gross_amount = 0
f_total_vat = 0
Do Until rstTable.EOF
oTable.Rows.Add
For intYCount = 0 To intYMax - 1
With oTable.Cell(Row:=intXCount, Column:=intYCount + 1).Range
If Not IsNull(rstTable.Fields(intYCount).Value) Then
Dim str_value As String
If (intYCount = 2) Then
f_total_gross_amount = f_total_gross_amount + rstTable.Fields(intYCount).Value
End If
If (intYCount = 3) Then
f_total_vat = f_total_vat + rstTable.Fields(intYCount).Value
End If
If (intYCount = 2 Or intYCount = 3) Then
str_value = String(12 - Len(CStr(rstTable.Fields(intYCount).Value)), Chr(32)) & Format(CStr(rstTable.Fields(intYCount).Value), "#0.00")
Else
str_value = CStr(rstTable.Fields(intYCount).Value)
End If
.InsertAfter Text:=str_value
Else
.InsertAfter Text:=""
End If
End With
Next intYCount
intXCount = intXCount + 1
rstTable.MoveNext
Loop
oTable.Rows.Add
With oTable.Cell(Row:=intXCount, Column:=2).Range
.InsertAfter Text:="Total"
End With
With oTable.Cell(Row:=intXCount, Column:=3).Range
.InsertAfter Text:=Format(CStr(f_total_gross_amount), "##########0.00")
End With
With oTable.Cell(Row:=intXCount, Column:=4).Range
.InsertAfter Text:=Format(CStr(f_total_vat), "##########0.00")
End With
oTable.AutoFormat Format:=wdTableFormatGrid8, ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows:=True
oTable.Select
With oDoc.Application.Selection
.Collapse Direction:=wdCollapseStart
.InsertParagraph
.Collapse Direction:=wdCollapseStart
End With
Set oTable = Nothing
Set oDoc = Nothing
Set oWord = Nothing
Create Textbox In Every Cell From A Word Table
Hallo everyone,
I have a table wich contains texts and images in every cell, I would like to select everything is in a cell and put it in a textBox,so I will have a textbox for every cell.
I try this
Count = 1
For currRow = 1 To (Selection.Tables(1).rows.Count)
For currCol = 1 To Selection.Tables(1).Columns.Count
Selection.GoTo What:=wdGoToBookmark, Name:="Bookmark_" & Count
Selection.Tables(1).Cell(currRow, currCol).Select
Selection.CreateTextbox
Selection.ShapeRange.Line.DashStyle = msoLineDash
Count = Count + 1
Next currCol
Next currRow
But I have an error anyone could help me?
Thany you.
Adelin
Word 97 - Bookmarks/table Cell Refs
Hi
I know how to create a simple bookmark in Word using VB, but is there a way to tell it to find a table cell ref and create the bookmark?
Thanks
Pendle
How To Retrive An Image From A Table Cell Of Word Doc
hi friends,
i have inserted an image using the following code-
wdapp.ActiveDocument.Range.InlineShapes.AddPicture("c:image1.gif")
how should i retrieve this image into a picture box without losing the quality of the image,
i have tried with the
range.copy
picture1.picture=clipboard.getdata
i got the image but the image quality is very poor!!
HELP ME OUT PLEAAZZZZZZ..
THANX.
How To Retrive An Image From A Table Cell Of Word Doc
hi friends,
i have inserted an image using the following code-
wdapp.ActiveDocument.Range.InlineShapes.AddPicture("c:image1.gif")
how should i retrieve this image into a picture box without losing the quality of the image,
i have tried with the
range.copy
picture1.picture=clipboard.getdata
i got the image but the image quality is very poor!!
HELP ME OUT PLEAAZZZZZZ..
THANX.
Word Table: Mixed Cell Widths ?
Please, help in this situation.
My Word-table has some splitted cells in a header.
I try to insert data to lower cells. But I have the message "Cannot access individual columns in this collection because the table has mixed cell widths. How to work with a table of such kind?
Thanks.
MSWORD Making One Word Bold In A Table Cell.
Hi
I am creating a report in word using tables in VB6.
One of the cells contains a surname and then two foren
ames for married
partners. I need to have the surname in bold and the
forenames as
normal.
When I do this I can make the whole cell bold or n
ormal. Can anybody
help?
Regards
Peter
Important Note: This E-Mail is confidential, it must not
be read,
copied, disclosed or used by any person other than the
above
named addressees. Unauthorised use, disclosure or copying is
strictly prohibited and may be unlawful. Eurostar (U.K.) L
imited
and Eurostar Group Limited disclaim any liability for any
action
taken in reliance on the content of this E-Mail. The c
omments
or statements expressed in this E-Mail are not necessarily
those
of Eurostar (U.K.) Limited, Eurostar Group Limited or any
subsidiaries or affiliates of either company.
Eurostar (U.K.) Ltd. Registered Office: Eurostar House, Wate
rloo
Station, London, SE1 8SE, Registered in England No. 246200
1
VAT No. GB 657 719 590
Eurostar Group Ltd. Registered office: Eurostar House, Water
loo
Station, London, SE1 8SE, Registered in England No. 379464
2
VAT No. GB 739 974 173
This email has been scanned for all viruses by the Mes
sageLabs Email
Security System on behalf of Eurostar. For more informatio
n on a proactive email security service working around t
he clock, around the globe, visit http://www.messagelabs.com
Change Font Bold Of A Cell In A Table In Word From VB
I've used some code from johnwm in thread222-589129 some time ago to help me make the table. From that I've figured out how to change the "header row" background color. Now I'm trying to change the "header row" font to bold but I'm having diffieculty. Can someone help. Here is the how I change the color of row 1 for each column.
CODE'This will change the color of the header row in the table
With MyRange.Tables.ITEM(1)
For g = 1 To .Columns.Count
' .Cell(1, g).Select.Font.Bold = wdToggle
.Cell(1, g).Shading.BackgroundPatternColor = wdColorYellow
Next g
End With
Problem Accessing A Merged Cell In A Word Table Using MACRO
Hi ,
I am writing a macro which converts a MS WORD table into particular format. I need to retain the structure of the table while doing so.
The main problem is that if a row consists of a merged cell then there is no means to identify this at runtime. If a merged cell has occured in the input table i need to place a identifier for the same in the output....
Could anyone please let me know how can i achive this ?
Thanks
Selecting Text In Word
How can I set a cursor in a spesific place in a Word document with a macro? I would need a code, that selects the path from hyperlink code just like user would have drag over it with mouse. Finding a link code is not the problem but dealing with select/cursor.
Table Cell Text Contains Box?
Hi
When I read table cell content into a variable, it contains cell text + some unkown character which is shown as small box.
How to filter that unwanted character from cell text content?
natrajv
Insert Cell Format & Get Cell Value Without Selecting Worksheet
Hello
I am trying to tidy up a workbook. I have several macro's, one of them insert a new line with different cell formats in to different worksheets and most of the others get a cell values for creating reports.
The only way I know of inserting / getting a cell value is to select the worksheet and run the macro
Sheets("Works Schedule").Select
' Run code
This way works but is their a way of running the macro with out selecting the worksheet to stop the workbook flickering between each sheet whiles the macro is running
Thanks
Tom
Selecting A Cell Based On Where The Active Cell Is
Firstly. Hello gurus, developers, lurkers and other bobs. It is a pleasure to find this place and meet you all.
Secondly. Here is the problemette that I am looking for assistance on.
I have been given an Excel spreadsheet to maintain and improve. What I am looking for is to be able to copy data from one worksheet to another with the following requirements. The data that I select is in worksheet 1, columns A and C which I then want to copy to worksheet 2. The process will be dependent on where the active cell is in worksheet 1, which could be anywhere within the range D3 to L1000. (I hope this makes sense)
Up until being given this spreadsheet to maintain I have never used any form of VB before. I have tried a multitude of searches here and on a few other sites and the results of those indicted using Range(ActiveCell, ActiveCell.End(xlToLeft)).Select in some way but so far I have been unable to make it function as required so I am open to suggestions.
Regards
Youngnutter
How Do I Make A Portion Of Text In Word Cell Bold?
I've created a word template with a table in it.
In one cell I am entering multiple lines. I'd like the first line (the name) to be bold.
I'm using asp and cannot figure out the correct property to call.
Here is part of the source code:
Code:
Set objWord = CreateObject("Word.Application") ' Create a Word object.
Set WordDoc = objWord.Documents.Add("C:Incident.dot") ' Start a document.
objWord.Application.Visible = False
With WordDoc
Open recordset here
Code:
Do While Not rsPeopleList.EOF
.Tables(7).Cell(row, col).Range.InsertAfter (rsPeopleList("LastName") & ", " & rsPeopleList("FirstName") & " " & rsPeopleList("MiddleName"))
.Tables(7).Cell(row, col).Range.InsertAfter (vbcrlf & vbcrlf)
If rsPeopleList("EmployeeRole") = "" Then
.Tables(7).Cell(row, col).Range.InsertAfter (vbcrlf)
Else
.Tables(7).Cell(row, col).Range.InsertAfter (rsPeopleList("EmployeeRole") & vbcrlf)
End If
.Tables(7).Cell(row, col).Range.InsertAfter ("Employee Number:" & vbTab)
If rsPeopleList("EmployeeID")="" Then
.Tables(7).Cell(row, col).Range.InsertAfter (vbcrlf)
Else
.Tables(7).Cell(row, col).Range.InsertAfter (rsPeopleList("EmployeeID") & vbcrlf)
End If
...
Thanks,
Julie
Fill Text Box In Word With Data From Excel Cell
Hi,
I have a very simple problem (I hope it is simple):
I have a Text Box in Word with no text entered.
In Excel (Sheet 1, Cell A1) is a text, e.g. "Hello World".
In Word I would like to fill the Text Box with the cell of Excel A1.
Can someone post a simple macro of how to achieve this?
On top of that, is there a way to create Text Boxes dynamically in Word and position each created text box?
Thanks in advance!
How To Link An Excel Cell To An Access Table Cell
I am trying to import an populated excel form into access using just specific cells (where the data is located) only. I am able to open excel and get the data from the cells but how can i assign them back to my access table? This is like importing a populated excel form into access database.
I used these to get my excel info
Set excel_app = CreateObject("Excel.Application")
excel_app.Visible = False
excel_app.Workbooks.Open FileName:=mypathname & myfilename
Set excel_sheet = excel_app
x= excel_sheet.cells(10, 4).Value 'To get the excel cell value'
y= excel_sheet.cells(12,4).Value
Now I want x to be assigned to table "AppendTable" in column "AppColumn1"
and y in column "AppColumn2"
help!!!
Extract Text From Table In Word
Hi,
I've been skimming through the threads and couldn't find QUITE this question.
I have a word document, with text and tables here and there (I don't know where they are in the document - they're spread throughout it).
I want to know:
1) How can I find the first table, then the next then the next etc...
2) Can I just collect ALL of the tables in the word documents into one object?
3) Once I find a table, how can I extract text from a specific cell in it.
Maybe go over ALL the rows then ALL the cells and look for the text.
How can I do that?
Thanks a lot people!
You're great!
- M00gl3
Replace Text In A Table In Word
Hello,
I'm using a word template in which i want to replace a certain word at a certain position for a newly created table.
How can i do this.
I have used this part of the code to find:
With objWord.ActiveDocument.Content.Find
.Text = table"
With .Replacement
.ClearFormatting
End With
.Execute Format:=True, Replace:=wdReplaceAll
End With
This does nothing then finding the word "table" but i want to create a selection or range so the i can replace this word for a table with for example 3 rows en 3 colums.
Can anyone help me out?
Kind regards,
Maruq
Export Text To Table In Word Document
I have an application in VB6 that perform some basic calculations. The calculations themselves are not particularly difficult, but are onerous when you have to repeat them again and again and put the results into a letter. The app works fine.
However, I would like some additional functionality whereby at the click of a button a user could export the results straight from the app into certain cells of a table in the Word document.
The document is a standard template - in other words it will always be the same.
However, i haven't the faintest idea how to approach it. I imagine I could get VB to query the document somehow and then insert data after it finds certain words. Could anybody please point me in the right direction?
Inserting Text In Table Created In Ms Word Using Vb
hai i have got 1 solution for the question post releating to creation of table in ms word which i am trying out ok now i have another doubt after creating table i have to insert text in that table and merge the table and do other formating like making bold and also to move the table
Word: How To Replace Text In A Table In A Header
Hi,
In a Word document exists a table in a header. How can I select text in a cell of this table and replace it with something else?
Thanks for your help!
Edited by - ELOOP on 2/17/2006 6:22:38 AM
Setting Text Properties In Word Table
hi.
i need to set some text to bold inside a cell of a word table
i'm using vb6.
attached is the sample code.
Set oTable = oDoc.Tables.Add(oDoc.Bookmarks("endofdoc").Range, 5, 2)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Borders.Enable = False
oTable.Cell(i%, 2).Range.Text = "Text1. Text2"
oTable.Cell(i%, 2).Range.Font.Underline = False
in the text property of the cell, i need to set "Text1" to bold,
and leave "Text2" as is, with regular font.
any idea how to do this? any help would be greatly appreciated.
thanks.
Need Help Selecting A Specified Cell
I am not a programmer, so bear with me. I'm doing this project for work, and I've pieced together a little Visual Basic knowlege over the past week; but I can't figure out how to move to a specific cell within my program.
Project: I have two worksheets. Sheet1 (in my code below it's called "CPForm") is an empty form. Basically, it contains two key pieces of info: 1. Down the rows (starting at A13, then A16... every third row) will go employee names; 2. Across the columns will go the days of the week in the format of (m/d... 5/9--> 7 columns total). Sheet2(called "DownLoad") is an exported Sheet from Quickbooks. In it are 3 columns: 1. Date; 2. Employee; 3. Hours worked for that day. Every line contains individual employee's hours for the day, and it continues for a 1 week period. I want to create a program that will, at the press of a button, copy each employee's name over to "CPForm", and then place the number of hours work in the correct cell in the table.
Problem: I have figured out most of it, but I can not figue out how to paste the hours in the correct cell on the CPForm.
Here is the code I've gotten so far:
Code:
Dim LastEmployee As String
Dim Hours As Single
Dim Day As Date
Sheets("DownLoad").Select
Range("A1").Select
Do Until x = 5
Do Until ActiveCell <> "" 'cycling down one line to next name
ActiveCell.Offset(1, 0).Range("A1").Select
x = x + 1
Loop
LastEmployee = ActiveCell 'putting the name in this variable
ActiveCell.Offset(0, -1).Range("A1").Select 'moves active cell to copy date to a variable
Day = ActiveCell
ActiveCell.Offset(0, 2).Range("A1").Select 'moves to put hours worked into a variable
Hours = ActiveCell
Sheets("CPForm").Select
Range("A13").Select
Do Until ActiveCell = "" Or ActiveCell = LastEmployee 'First name will go in A13.. this will cycle down to first open space
ActiveCell.Offset(3, 0).Range("A1").Select
Loop
ActiveCell = LastEmployee 'Puts the employee name in proper place
'???????????
'I can't figure out how to index over to the correct date column
'and place the hours
End Sub
All help is appreciated
RESOLVED Need To Place Text In MsFlexGrid Cell, It Should Append If Cell Already Have Text
Hai ,
i exactly need the logic i think so
If i am populating the grid within the While Statement and the For Loop,
for the first time with this code i am able to place the information in the Cell, but for the second time i am not able.
There may be a chance of having two records with the same date at that time i need to append the information with the existing content in the grid , but if its going to put the information for the first tiem then it should remove the existing date in the Cell. Currently i tried with this code. its not working. Can any one help me to clear this.
Code:SQL = "select * from NewAssg where TIEtsOspas between #" & Month(lsFirstDate) & "/01/" & cboYear.Text & "# And #" & Month(lsFirstDate) & "/" & Day(DateAdd("m", 1, lsFirstDate) - 1) & "/" & cboYear.Text & "#"
rst.Open SQL, cnnNew, adOpenStatic, adLockReadOnly, adCmdText
If rst.RecordCount >= 1 Then
rst.MoveFirst
While Not rst.EOF
For iRow = 1 To grd.Rows - 1
For jCol = 1 To grd.Cols - 1
If Format(Month(rst.Fields("TIEtsOspas")) & "/" & grd.TextMatrix(iRow, jCol) & "/" & cboYear.Text, "mm/dd/yyyy") = Format(rst.Fields("TIEtsOspas"), "mm/dd/yyyy") Then
grd.Row = iRow: grd.Col = jCol: grd.CellAlignment = flexAlignLeftCenter
PrvVal = grd.TextMatrix(iRow, jCol)
If grd.TextMatrix(iRow, jCol) = grd.TextMatrix(iRow, jCol) Then
grd.TextMatrix(iRow, jCol) = "EqpName:" & rst.Fields("EqpName") & vbCrLf & "StartDate:" & Format(rst.Fields("TIEtsOspas"), "mm/dd/yyyy") & vbCrLf & "Duration:" & rst.Fields("DOffStrm")
Else
grd.TextMatrix(iRow, jCol) = grd.TextMatrix(iRow, jCol) & vbCrLf & "-------- x -------" & vbCrLf & "EqpName:" & rst.Fields("EqpName") & vbCrLf & "StartDate:" & Format(rst.Fields("TIEtsOspas"), "mm/dd/yyyy") & vbCrLf & "Duration:" & rst.Fields("DOffStrm")
End If
End If
Next
Next
rst.MoveNext
Wend
End If
Thankyou,
Chock.
Edited by - chs on 7/4/2005 12:41:45 AM
How Can I Fill Out A Table In A Word Document With The Text Of Textboxes Using Vb6?
i have a command button on my form and 6 textboxes as well (text1,text2,...,text6) and also there is a word document called mike.doc at C:mike.doc. this word document has only one empty 2x3 table in.
what i want to do is:
cell[1]= text1.text
cell[1]= text2.text .............................
whats the code to do that?
i have searched everywhere, nobody has helped so far with this, nobody knows.
thanks in advance.
Word Object: Accesing Text In Table: URGENT!
Hey
How do I access the text in a cell of my table?
For instance if i have a table with more than one row, and i need to know the value (text) which is present on column 1 of row 4.
I went as far as:
objWdDoc.Tables(1).Rows(4).Cells(1).
but then i don't know the attribute which holds the text value...
Can you help me please?
Selecting A Excel Cell From Vb6
How to read data from Excel. Make sure you reference MS Excel Object Library 8.0 or 9.0 in VB.
VB Code:
Private Sub Command1_Click()Dim row As IntegerDim col As IntegerDim row_end As IntegerDim col_end As IntegerDim dblArray() As Double Dim objExcel As Excel.Application On Error Resume Next ' grab Excel if open Set objExcel = GetObject(",Excel.Application") ' if error - not open If Err.Number <> 0 Then ' open it Set objExcel = CreateObject("Excel.Application") End If Err.Clear On Error GoTo 0 ' make it visible objExcel.Visible = True ' open normal objExcel.WindowState = xlNormal ' open file objExcel.Workbooks.Open FileName:="C:Book5.xls", ReadOnly:=True ' run macro - not used here 'objExcel.Run "Macro1" ' set up aray to hold values read from Excel ReDim dblArray(1 To 200) ' select a column objExcel.Range("F1").Select ' get max rows row_end = ActiveCell.End(xlDown).Rows.row ' get max columns - not used here 'col_end = ActiveCell.End(xlToRight).Columns.Column ' to grab one cell - not used here 'strMyVar = objExcel.Cells(1, 2) row = 1 col = 6 ' colume F ' loop from row 1 to row_end, column 6 Do Until row > row_end dblArray(row) = objExcel.Cells(row, col) row = row + 1 Loop ' cut array to proper size ReDim Preserve dblArray(1 To row - 1) ' show grabbed values For row = 1 To UBound(dblArray) Debug.Print dblArray(row) Next row ' close workbook - no save objExcel.ActiveWorkbook.Close SaveChanges:=False ' close Excel objExcel.Quit ' clean up Set objExcel = Nothing ' close form Unload MeEnd Sub
Selecting A Certain Cell In Excel
Hi all,
I am working on a project that is using the VB in Excel. I am trying to figure out how to select a certain cell. Basically, I have a column of numbers and these numbers start at 21 then go down to about 3 and then climb back to 21. They are in one column and consist of 4,120 rows. I have an inputted value, say 13, I need to search though the column of numbers and select the first cell that is just before the cell that is <= 13. Then I need to use that row number to identify where the data should start being used for calculation i.e. delete all data above that row indicator. An suggestions would be greatly appreciatted.
Continuoulsy Selecting A Cell In Column B
Hi,
I'm running a loop which, at the end of each row, offsets back to the corresponding cell value in column B. Each row in column B contains a name which I then enter in a message box to prompt the user.
I can write code to select a name in a specific cell, such as B2, B3 etc but i'm unsure how to write the code to continuously know to select the value in column B of a particular row.
A section of my code looks like...
Ans = Msgbox Sheets("Records").range("B2").column
I'm stuck at the moment and any help would be greatly appreciated. Thanks.
Selecting A Range {until Empty Cell}
Hi
I'm trying to write code that will select a range of cells (in column A) but will stop selecting once an empty cell is detected.
I'm not sure if this code should include a do-until loop?
I would greatly appreciate any help.
Thanks
|