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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word automation 1

Status
Not open for further replies.

vbenlieva

Programmer
May 7, 2005
10
0
0
BG
I use VFP 9.0
I create a word object, from an existing word document and I want to place some information in the document. In the program I have:

.....
objWord=CREATEOBJECT("Word.Application")
oDoc = objWord.Documents.Add("&mydoc")
*!* mydoc is the name of an existing word document
objWord.ActiveDocument.paragraphs[1].range.select()
objWord.Selection.TypeText('TO: ')
objWord.ActiveDocument.paragraphs[2].range.select()
objWord.Selection.TypeText('FAX:')
.....

When I execute the program.prg it works, but when I made an exe file it generated the following error:

"Member ACTIVEDOCUMENT does not evaluate to an object"

Where am I wrong?
Thanks in advance
 

Instead of using objWord.ActiveDocument, just use oDoc.

In other words:

Code:
objWord=CREATEOBJECT("Word.Application")
oDoc = objWord.Documents.Add(mydoc)
*!* mydoc is the name of an existing word document
oDoc.paragraphs[1].range.select()
objWord.Selection.TypeText('TO: ')
objWord.ActiveDocument.paragraphs[2].range.select()
objWord.Selection.TypeText('FAX:')

Not releated to your question, but I've also removed the macro expansion in the second line above -- just pass the document name as a variable.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
It doesn't work. It generated the error:
"ODOC is not an object"
 
It doesn't work. It generated the error:
"ODOC is not an object"

What is in the variable MyDoc? Does it have the fully qualified path name to the document? Does the document exist? Are there apac es in the file name? If there are, you need the macro expansion that Mike removed from your code.





Marcia G. Akins
 

vbenlieva,

Marcia's right. If the document name includes spaces, you will need the macro expansion after all (sorry, I should have remembered that).

Come to think of it, why are using the Add method to open the document? If you use the Open method instead, you will get a useful error message if the method fails, which is obviously what's happening here. That would also explain your original problem.

Try changing .Add to .Open and let us know what you see.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
In my variable MyDoc, I didn't have the full path.
When I changed with the correct path .... it works now!!!
Thanks
Cheers :)
 
>> Marcia's right. If the document name includes spaces, you will need the macro expansion after all (sorry, I should have remembered that).

Why? The variable is being passed as a parameter, so macro expansion shouldn't be involved. It's possible that Word prefers to have quotes around the file name, in which case you could do this:

oDoc = objWord.Documents.Add( ["]+mydoc+["] )

I try to avoid macro expansion in every place that it isn't needed... it only obscures things, making debugging harder.


- Bill

Get the best answers to your questions -- See FAQ481-4875.
 

Bill,

The variable is being passed as a parameter, so macro expansion shouldn't be involved.

I must have been having a moment of senility. If the filename contains spaces, then of course it is better not to do macro expansion.

Thanks for putting us right.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top