PDA

View Full Version : Format newly created table (that is a paste of excel data)



RECrerar
08-17-2009, 07:23 AM
[Hi,

I am using the following code to insert some copied data as a table in word


' Insert section breaks so that landscape page set up only applied to current segment
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.MoveUp Unit:=wdLine, Count:=1
With Selection.PageSetup
.Orientation = wdOrientLandscape
.SectionStart = wdSectionNewPage
End With
Selection.PasteExcelTable True, False, True


What I then need to be able to do is identify the newly created table in the document so that I can format it. I'm quite new to word VBA so the question is: How do I identify the table?

Is it possible to create a bookmark when I create the table? or is there a way to link to the current table?

The table is currently just inserted at the cursor position. It could be anywhere in the document and will have similar content to several other tables, meaning I can't use a search for a specific heading.

I hope you can help

Robyn

RECrerar
08-17-2009, 09:36 AM
what I have done is just added the following to the end of the code which appears to work fine

Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)

If there is a better way I would be interested in knowing, else this seems fine to me