table manipulation in VBA

S

Shell

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
 
D

Dave Lett

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
 
S

Shell

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
 
C

Cindy M.

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 :)
 
D

Dave Lett

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
 
J

Jean-Guy Marcil

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

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top