Solved

Word Automation

Posted on 2001-08-07
6
619 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now