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!

How to select table in Word from VFP when visible = .F. for Word app

Status
Not open for further replies.

ctbaker

Programmer
May 8, 2003
26
US
When I run the code with the .visible property set to .T. and Word runs in the foreground everything works fine but with the .visible property set to .F. I get the following error when it gets to the last line of code shown below:

"OLE IDispatch exception code 0 from Microsoft Word: The requested member of the collection does not exist..."

Between the creation of the table and the selection of it I have entered data into cells and done some formatting via VFP commands.

I am using VFP 7 and Word 2000. Any ideas what the fix is? I don't have the option of going to a newer copy of Word either.

Thanks,
Chad

Code:
*-- 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 = 3
        .Selection.Homekey(6)
		.Visible = .F.
        .ActiveWindow.ActivePane.View.ShowAll = 0
        .Selection.Font.Name = "Times New Toman"
        .Selection.Font.Size = 12
   	ENDWITH

<snip>

*-- Construct Project Development expenditures table
	owRange = oWord.Selection.Range
	oWord.Activedocument.Tables.Add(owRange, 4, ln_numcols)
	oTable = oWord.ActiveDocument.Tables(1)

<snip>

oWord.Selection.Tables(1).Select
 
Chad,

I just ran your code. It seems to work OK, both as it stands, and also if I make oword.visible = .T.

This was in Word 97. I can't see why it would be different in 2000, but perhaps someone else will try it to confirm.

Mike



Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike,

Thanks for the reply.. I commented out some code so that it runs exactly as I presented it and you know, I don't get any error either!! Here is the code that I run when I get the error, it replaces the 2nd <snip> and below. When I get to the tables(1).select command it definitely gives me an error. You should also be able to skip the FOR loop as it just sets the column widths for the table. I tried to cut out extra code I thought didn't matter to the problem at hand, apparantly I was wrong!

Code:
	FOR i = 1 TO 5
		oWord.Selection.SelectColumn
		oWord.Selection.Columns.PreferredWidth = la_colw[i]		&& Set column width for individual columns
		oWord.Selection.Range.Cells(1).VerticalAlignment = 3
		oWord.Selection.Move(1,1)
	ENDFOR
	WITH oWord
		.Selection.MoveUp(5,3)
		.Selection.MoveLeft(1,4)
	 	.Selection.SelectRow
	 	.Selection.ParagraphFormat.Alignment = 1
	 	.Selection.Cells.Shading.Texture = 1000						&& Shading in percent; 200 = 20.0%
		.Selection.Font.Color = 16777215
		.Selection.SelectCell
		.Selection.Move(1,1)
		.Selection.MoveUp(5,1)
		.Selection.Move(1,1)
		.Selection.TypeText("Programmed")
		.Selection.MoveRight(1,1)
		.Selection.TypeText("Expended")
		.Selection.MoveRight(1,1)
		.Selection.TypeText("Est. To Complete")
		.Selection.MoveRight(1,1)
		.Selection.TypeText("TOTAL")
		.Selection.MoveDown(5,1)
		.Selection.MoveLeft(1,4)
		.Selection.TypeText("PA&ED")
		.Selection.MoveRight(1,1)
		.Selection.MoveRight(1,1)
		.Selection.MoveRight(1,1)
		.Selection.MoveRight(1,1)
		.Selection.MoveDown(5,1)
		.Selection.MoveLeft(1,4)
		.Selection.TypeText("PS&E")
		.Selection.MoveRight(1,1)
		.Selection.MoveRight(1,1)
		.Selection.MoveRight(1,1)
		.Selection.MoveRight(1,1)
		.Selection.MoveDown(5,1)
		.Selection.MoveLeft(1,4)
		.Selection.TypeText("TOTAL")
		.Selection.Tables(1).Select
	 	.Selection.Paragraphs.Indent
	 	.Selection.Paragraphs.Indent
	 	.Selection.Paragraphs.Indent
	 	.Selection.Paragraphs.Indent
		.Selection.ParagraphFormat.TabStops.ClearAll
		.Selection.ParagraphFormat.RightIndent = 0
		.Selection.MoveRight(1,1)
		.Selection.TypeText(CHR(10))
	 ENDWITH

Thanks,
Chad
 
I rearranged the code a little but to try and resolve the select table error and now I get this error:

"OLE Idispatch exception code 0 from Microsoft Word: The SelectRow method or property is not available because some or all of the object does not refer to a table..."

Any idea what issue this is pointing to?

It seems like the .MoveUp, .MoveRight, etc. commands are not being acted upon when Word is running in the background.

Any ideas?

Thanks,
Chad
 
I resolved the issue on my own. Apparantly the .MoveUp and .MoveDown commands don't work when word is running as a background process. By making all modifications to the table on a cell basis and using .MoveLeft and .MoveRight commands only, I was able to do what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top