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

Error using MS Word Automation

Status
Not open for further replies.

MdotButler

Programmer
Jan 18, 2006
104
US
I have a situation where I am creating a word document from a template. In itself the document is being created as expected. The problem I am encountering is upon exiting word. A dailog box is presented with the following error:
Code:
The file is in use by another application or user.
(C:\Documents and Settings\...\Notmal.dot)
The dialog only has an [OK] button which I am then presented with a save dialog, to save "Normal.dot". If I try to save it I get the same error as above. I then [cancel] the save dialog. Then when I try to exit word, I again get another dialog stating:
Code:
Changes have been made that affect the global templace, Normal.dot, Do you want to save those changes?
If I select [Yes] the first error is presented again, selecting [No] and word closes. With all the above said I am trying to just get out cleanly. I am enclosing the pertinent parts of the VFP code to see if there is something I am doing wrong.
Code:
lcTemplate=LOCFILE('BidTemplate.dot','dot','Template:')
loWord=CREATEOBJECT('Word.Application')
loDocument=loWord.Documents.Add(lcTemplate)
....
lcFileName='d:\bid.doc'
loDocument.SaveAs(lcFileName)
loWord.Visible=.T.
loWord.Activate()
RELEASE ALL LIKE lo*
TIS
Mark
 
Mark,

Have you tried doing this manually in Word while running the macro recorder to see how Word does it itself?

Do you get this error whether or not the user has another document open at the time?

Stewart
 
Thanks for the response Stewart...

The above code is behind the click method of a button. I have run the process in debug, line by line and the program or function is doing as it should. In the program where you see ... it is actually getting information from a table and placing it in the word document.

I have not turned on the macro recorder to see what is happening but I did stumble on the cause. If I have outlook open, which uses word as the email editor, the above errors occur. If Outlook is shut down, the errors go away.

Why would having outlook open lock the "Normal.dot" file? Secondly what is actually being changed in the "Normal.dot" file which requires it to be saved? I will try the macro record and see if that shows anything.

Thanx
Mark

run it
 
Try This:

oWord = Createobject("word.application")
oWord.Documents.Open("c:\BidTemplate.dot")
oWord.ActiveDocument.SaveAs("C:\testdoc.doc")
oWord.Visible = .T.
oword.Quit
RELEASE oword
 
Why would having outlook open lock the "Normal.dot" file?

Don't know. But I have seen exactly the same error message when running Outlook and Word interactively, which suggests that this is not a fault in your VFP code. Sorry ... I know that doesn't help much.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Just tried it with Outlook open and did not have a problem with saving or shutting down word (with and without Word as the email editor).... tried it about 6 times... This must be erratic as I cannot reproduce the error
 
Try passing the lcFilename with another set of quotes.
in my code i do the following in the saveas(
Code:
cobfilename='"'+'z:\obit\'+Proper(Trim(ln_dec))+[.]+Proper(Trim(fn_dec))+[.]+m.retstring+'.obt.doc'+'"'		

If .Not. File(&cobfilename)
		loDoc  = loWord.documents.add(&cfilename)			&& create new document based on template file
		loDoc.SaveAs(&cobfilename)					&& save with the correct name
wjwjr
 
The usual problem with normal.dot is caused by a renegade addin. Norton AV's Office addin is notorious for this. It can safely be removed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top