Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Fri, 1 Aug 2008 15:38:05 +0800,    group: microsoft.public.word.tables        back       


how to align table to the center in word VBA   
Hi,

I wonder if there is a way of automatically aligning table to the center. I 
have a macro that would allow user to insert a table with their desired 
number of rows and columns and would place the table right in the center. 
This way, when user tries to change the left or right margins, it would 
always stay in the middle.

I have got the following code (i got from recording the macro)but it only 
applies the paragraph, not the whole table. Because after inserting the 
table, i highlighted the table and saw that it's not centered but is left.

Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=myRow, 
NumColumns:= _
        myCol, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= 
_
        wdAutoFitFixed
    With Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = True
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = True
        
    End With
    
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.TypeText Text:="Figure 1. Testing"
Selection.MoveLeft Unit:=wdCharacter, Count:=10
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft   

Hope i explained it well.

Thank you in advance

url:http://www.ureader.com/gp/1018-1.aspx
date: Fri, 1 Aug 2008 15:38:05 +0800   author:   daniel lie

Re: how to align table to the center in word VBA   
Hi Daniel,

Selection.Tables(1).Rows.Alignment = wdAlignRowCenter


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
date: Fri, 01 Aug 2008 12:52:37 +0200   author:   Helmut Weber

Re: how to align table to the center in word VBA   
It works now.

Thank you for your help.

url:http://www.ureader.com/msg/10182802.aspx
date: Mon, 4 Aug 2008 06:29:25 +0800   author:   daniel lie

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us