Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Table in Word via FoxPro 1

Status
Not open for further replies.

ctbaker

Programmer
May 8, 2003
26
US
Hello,

I have found some great threads on here pointing to good links on Microsoft's website which gave me a lot of information on how to control Word from FoxPro but I am having one problem.

I am trying to set the vertical alignment for text in a particular cell in a table to bottom from top and it won't work. I can set the vertical alignment to top and center but when I set it to bottom I get an error. How do I get the vertical alignment to set as bottom?

Thanks!
Chad

The offending line of code is:

oWord.Selection.Range.Cells(1).VerticalAlignment = 1

When set to 0 I get vertical = top
When set to 1 I get vertical = center
When set to 2 I get error = OLE IDispatch exception code 0 from Microsoft Word: 'VerticalAlignment' is not a by reference property...

My total code is below:

LOCAL oWord
LOCAL ln_numcols
DIMENSION la_colw(5)

ln_numcols = 5
la_colw[1] = 100
la_colw[2] = 220
la_colw[3] = 60
la_colw[4] = 65
la_colw[5] = 65

*-- Create the OLE object in WinWord
oWord = CREATEOBJECT('Word.Application')

*-- Base the new document on the NORMAL template
oWord.Documents.Add

*-- Display WinWord's application window so we can see what is happening.
WITH oWord
.ActiveWindow.View.Type = 1 && Switch to normal view. Page view=3
*!* .ActiveWindow.ActivePane.View.SeekView = 0 && Open main document.
.Selection.Homekey(6) && Go to top of document.
.Visible = .T. && Make Word visible.
.Application.Activate && Bring Word forward.
.WindowState = 0 && Show Word in normal state. Maximized=1
.ActiveWindow.ActivePane.View.ShowAll = 0 && No nonprinting items.
.Selection.ParagraphFormat.Alignment = 1 && Set Text Alignment; 1 = Center
.Selection.Font.Name = "Arial" && Set Font Type
.Selection.Font.Size = 8 && Set Font Size
.Selection.ParagraphFormat.LineSpacingRule = 4 && Set Line Spacing Rule; 4 = Exactly
.Selection.ParagraphFormat.LineSpacing = 8.5 && Set Line Spacing to 8.5 pt
ENDWITH

*-- Generate the table and insert form fields where appropriate.
owRange = oWord.Activedocument.Range(0,0)
oWord.Activedocument.Tables.Add(owRange, 3, ln_numcols)
oTable = oWord.ActiveDocument.Tables(1) && Assign a table object

FOR j = 1 TO 5
oWord.Selection.SelectColumn
oWord.Selection.Columns.PreferredWidth = la_colw[j] && Set column width for individual columns
oWord.Selection.Range.Cells(1).VerticalAlignment = 1
oWord.Selection.Move(1,1)
ENDFOR

*-- Build column headers
WITH oWord
.Selection.Homekey(6)
.Selection.TypeText("Project #" + CHR(10) + "Allocation Amount" + CHR(10) + "County" + CHR(10) + "Dist-Co-Rte" + CHR(10) + "Post mile")
.Selection.Move(1,1)
.Selection.TypeText("Location" + CHR(10) + "Project Description")
.Selection.Move(1,1)
.Selection.TypeText("EA" + CHR(10) + "Program")
.Selection.Move(1,1)
.Selection.TypeText("Budget Year" + CHR(10) + "Item #" + CHR(10) + "Program" + CHR(10) + "Codes")
.Selection.Move(1,1)
.Selection.TypeText("State" + CHR(10) + "Federal" + CHR(10) + "Total Amount")
ENDWITH
 
You nailed it!! thanks!!!

Why the settings go 0,1,3 is beyond me!

A probably naive question.. How do you find the values of the wd__________ variables in Word?

Thanks,
Chad
 
TOOLS - OBJECT BROWSER

Then open up the Microsoft Word Object Library...this will be located on the COM (tab) of the open dialog box you get when opening something new in the object browser...then once you have it opened look under the classes & members list (treeview) and you will see a "Constants" node, open that up and you will have access to all the constants and their values...such as the one in question:

Constant wdCellAlignVerticalBottom = 3
Hex: 0x00000003, Bin: 00000011
Member of Word.WdCellVerticalAlignment

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Take a look at VFP's Form.Colorsource property. Choices are 0, 4, and 5. Nothing says these settings have to be sequential and they frequently aren't.

Slighthaze has already answered your question on locating the values.

To take it a step further, open an empty code window and drag the "Constants" node from the object browser to the code window. VFP will write #DEFINEs for all the Word constants.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top