[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
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.
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?
Re: VB-Write in a Table using word