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

Word Macro

Status
Not open for further replies.

TrevJones

Programmer
Nov 20, 2000
37
GB
I am using a batch file to open a document in word and run a macro against it using the /m switch. Normally this works fine. However, if the file name doesn't exist, word just hangs and expects a key press to clear a message box. This code needs to be run in batch mode without user intervention. Is there any switch or way around this to force word to fail and quit itself?

Thanks
Trevor
 
i'm not 100% sure but try the line
if exist <filename>
this should only run the code in the batch file if that particular filename exists.
 
I've used the following code in Word macros to see if a file is a zero byte file. If the file is a zero byte file, it won't process the print function.

Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFile = objFSO.GetFile(&quot;path of file name&quot;)

If objFile.Size > 0 Then
GoTo XXXX
Else
GoTo ZZZZZ
End If

Hope this helps.
 
Thanks for the replies. The problem i had was that the filenames were being generated in part by parameters being passed in. I had the If exists statement in the code but due to the parameter, the filename had a space in it. This meant that the IF statement didn't work (I assume it was because in effect it was working on two separate file names)and it just processed the next line of code (the call to word.)

I have tried putting error handling in the macro to deal with this but the error that Word throws up seems to happen before it runs the macro.

Thanks
 
if the filename has spaces in it i think you can put it in &quot;quotes&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top