Link to home
Start Free TrialLog in
Avatar of robertsmith28
robertsmith28

asked on

Word Automation

I'm using Excel '97 and trying to produce a report in Word '97. I've created a table using the following code but I want the table itself to be aligned to the right-hand side of the page and for the right margin to be smaller than the default - how can I acheiev this? Any comments greatly appreciated:

Dim wordapp As Word.Application
Dim WordDoc As Word.Document
Set wordapp = CreateObject("Word.Application")
Dim mytable As Word.Table
With wordapp
        .ScreenUpdating = False
        .Visible = True
        .WindowState = wdWindowStateMaximize
        .Documents.Add
Set WordDoc = .ActiveDocument
End With
Set mytable = WordDoc.Tables.Add(myRange, 6, 1)
With mytable
        .Cell(1, 1).Range.InsertAfter "Network Transport Monthly Report"
        .Cell(1, 1).Shading.BackgroundPatternColorIndex = wdBlack
        .Cell(1, 1).Range.Font.ColorIndex = wdWhite
        .Cell(1, 1).Range.Font.Name = "Arial"
        .Cell(1, 1).Range.Font.Size = 14
        .Cell(1, 1).Range.Font.Bold = True
        .Columns.Width = 310
        .Rows(1).Height = 20
        .Rows(1).Alignment = wdAlignRowLeft
        .Rows(1).Cells.VerticalAlignment = wdCellAlignVerticalBottom

End With
Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

for align right try :
Selection.ParagraphFormat.Alignment = wdAlignParagraphRigh

for margins try :
With ActiveDocument.PageSetup
        .Orientation = wdOrientPortrait
        .TopMargin = InchesToPoints(1)
        .BottomMargin = InchesToPoints(1)
        .LeftMargin = InchesToPoints(0.4)
        .RightMargin = InchesToPoints(0.8)
        .Gutter = InchesToPoints(0)
        .HeaderDistance = InchesToPoints(0.5)
        .FooterDistance = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(8.5)
        .PageHeight = InchesToPoints(11)
End with

hopes this helps
Avatar of robertsmith28
robertsmith28

ASKER

Thanks Datrias,
How do I indicate that my table is the paragraph to be right-aligned?
Sorry, this is the first time I've used Word Automation and its confusing for me...
I tried adding:

 Set mytable = WordDoc.Tables.Add(myRange, 6, 1)
    mytable.Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

but I get an error message stating 'Object does not suppport this property or method'. Any ideas what I'm doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of calacuccia
calacuccia
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again, calacuccia, just what I wanted. Thanks to Datrius also for the initial help, cheers!