Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

table manipulation in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shell - 21 Aug 2006 14:38 GMT
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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.