Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

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
0
robertsmith28
Asked:
robertsmith28
  • 3
  • 2
1 Solution
 
Jonathan KellyCommented:
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
0
 
robertsmith28Author Commented:
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...
0
 
robertsmith28Author Commented:
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
calacucciaCommented:
Hi robert,

Best way to accomplish this is to try and play with the leftIndent of the table:

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(wordapp.Selection.Range, 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
       .Rows.SetLeftIndent 200, wdAdjustNone
End With
0
 
robertsmith28Author Commented:
Thanks again, calacuccia, just what I wanted. Thanks to Datrius also for the initial help, cheers!
0
 
calacucciaCommented:
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now