Solved

Word Automation

Posted on 2001-08-07
6
617 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 17

Accepted Solution

by:
calacuccia earned 150 total points
Comment Utility
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
Comment Utility
Thanks again, calacuccia, just what I wanted. Thanks to Datrius also for the initial help, cheers!
0
 
LVL 17

Expert Comment

by:calacuccia
Comment Utility
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

743 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

15 Experts available now in Live!

Get 1:1 Help Now