|
-
Apr 27th, 2006, 12:19 PM
#1
Thread Starter
Lively Member
[RESOLVED] VB-Write in a Table using word
Hi,
I want to create a table with just 1 row and 2 cols, each col has different values.
When I try to write in that specific column, it just vanishes and writes only the last value.
Please help
for c=1 to 2
If c = 2 Then
oTable.Cell(1, c).Range.Text = "Customer Ship To: "
oTable.Cell(1, c).Range.Text = "Test: "
oApp.Selection.TypeParagraph
end if
Next
it write only Test and not Customer Ship To
-
Apr 28th, 2006, 02:17 PM
#2
Fanatic Member
Re: VB-Write in a Table using word
Since nobody has replied.......I've never done macros in Word, but would guess that using the macro recorder would be very instructive. It certainly is in Excel.
-
Apr 28th, 2006, 04:31 PM
#3
Lively Member
Re: VB-Write in a Table using word
Unless I'm mistaken, your code is doing exactly what it should.
The code only runs with c = 2, so the For statement seems pointless.
With c = 2, the code will first add "Customer Ship To:" to cell(1,2) and then overwrite this value with "Test:" which is all you are left with.
If you wanted to add headers to column 1 and 2, you could simply write:
VB Code:
Sub LoadTable()
Dim oTable As Table
Dim TablePos As Range
'This will insert your table at a bookmarked position named "Table1"
Set TablePos = ActiveDocument.Bookmarks("Table1").Range
Set oTable = ActiveDocument.Tables.Add(Range:=TablePos, _
NumRows:=1, NumColumns:=2)
'Add first header
oTable.Cell(1, 1).Range.Text = "Customer Ship To: "
'Add second header
oTable.Cell(1, 2).Range.Text = "Test: "
End Sub
Although it seems unecessary to write code for this in the first place.
I suspect there is more to this than just adding 2 headers to a table? Exactly what are you trying to achieve?
Last edited by New2vba; Apr 28th, 2006 at 04:43 PM.
Reason: Modify code to insert table as well
"Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )
-
Apr 28th, 2006, 06:16 PM
#4
Thread Starter
Lively Member
Re: VB-Write in a Table using word
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|