I can add a table to a word document using VBA. But How do I, in code, add a
few blank lines to the document before I add the new table?
Thanks

Signature
Shell
Dave Lett - 21 Aug 2006 15:18 GMT
Hi Shell,
You can use something like the following (many, many ways to do this,
though):
'''inserts three paragraphs in the current selection
Selection.TypeText vbCrLf & vbCrLf & vbCrLf
HTH,
Dave
>I can add a table to a word document using VBA. But How do I, in code, add
>a
> few blank lines to the document before I add the new table?
>
> Thanks
Shell - 21 Aug 2006 15:28 GMT
I don't think I was clear enough. I already have one table in the document.
I need to add a second table (which I do). I want to place the second table
AFTER the first table with a few blank lines in between. I don't know how to
place the cursor (in code) after the first table and add some lines.
Shell

Signature
Shell
> Hi Shell,
>
[quoted text clipped - 12 lines]
> >
> > Thanks
Dave Lett - 21 Aug 2006 15:35 GMT
Hi Shell,
You can use something like the following:
Dim oRng As Range
Set oRng = ActiveDocument.Tables(1).Range
oRng.Collapse direction:=wdCollapseEnd
oRng.InsertAfter Text:=vbCrLf & vbCrLf & vbCrLf
oRng.Collapse direction:=wdCollapseEnd
ActiveDocument.Tables.Add Range:=oRng, NumRows:=3, NumColumns:=3
HTH,
Dave
>I don't think I was clear enough. I already have one table in the
>document.
[quoted text clipped - 23 lines]
>> >
>> > Thanks
Cindy M. - 21 Aug 2006 15:32 GMT
Hi =?Utf-8?B?U2hlbGw=?=,
> I can add a table to a word document using VBA. But How do I, in code, add a
> few blank lines to the document before I add the new table?
Here's one way:
Sub AddTextAndTable()
Dim rng as Word.Range
Dim tbl as Word.Table
Set rng = ActiveDocument.Content
rng.Collapse wdCollapseStart
rng.Text = "Some text" & vbCR
rng.Collapse wdCollapseStart
ActiveDocument.Tables.Add(Range:=rng, NumRows:=3, NumColumns:=3)
End Sub
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
Jean-Guy Marcil - 21 Aug 2006 15:41 GMT
Shell was telling us:
Shell nous racontait que :
> I can add a table to a word document using VBA. But How do I, in
> code, add a few blank lines to the document before I add the new
> table?
WIth the Selection object:
With Selection
.HomeKey wdStory
.TypeText vbCrLf
.TypeText vbCrLf
.TypeText vbCrLf
End With
With the Range object:
Dim rgeDoc As Range
Set rgeDoc = ActiveDocument.Content
With rgeDoc
.Collapse wdCollapseStart
.InsertParagraph
.Collapse wdCollapseEnd
.InsertParagraph
.Collapse wdCollapseEnd
.InsertParagraph
End With

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org