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
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