Solved

Word Automation

Posted on 2001-08-07
6
625 Views
Last Modified: 2012-06-27
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
Comment
Question by:robertsmith28
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 6359380
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
 

Author Comment

by:robertsmith28
ID: 6359457
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
 

Author Comment

by:robertsmith28
ID: 6360796
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 17

Accepted Solution

by:
calacuccia earned 150 total points
ID: 6372060
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
 

Author Comment

by:robertsmith28
ID: 6378995
Thanks again, calacuccia, just what I wanted. Thanks to Datrius also for the initial help, cheers!
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 6379018
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help exporting Access table into multiple Excel worksheets 6 25
Changing a line of VBA using VBA 3 32
Dinamic report to Crosstab query 9 31
ADODB problem 20 35
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question