SaveAs Problem

M

MarkS

Hi,

I have the following line of code within an Application :

objWordApp.ActiveDocument.SaveAs strTargetFolder & "\" & strFileName &
".pdf", wdFormatPDF

objWordApp.ActiveDocument.Close wdDoNotSaveChanges

objWordApp.quit

I seems that Word is quitting prior to writing the PDF completely as the
file gets written to the disc but seems to be locked or not saved correctly
and will not display. If I remove the .quit the file gets successfully
written and I can later view it. Is there any way of testing to ensure the
save has completed (a property etc) prior to quiting.

Thanks
 
S

Shasur

You can try to loop through for few seconds to check if the file has been
created:

objWordApp.ActiveDocument.SaveAs strTargetFolder & "\" & strFileName &
".pdf", wdFormatPDF

iCtr = 0
Do
Sleep 8000
If Len(Dir(strTargetFolder & "\" & strFileName &
".pdf", vbNormal)) <> 0 Then Exit Do
iCtr = iCtr + 1
Loop Until ((blnFileFound = True) Or iCtr = 20)


objWordApp.ActiveDocument.Close wdDoNotSaveChanges

objWordApp.Quit

The above will check every eight seconds (to a maximum of twenty times) for
the presence of PDF file

I have used the Sleep API function. Please include the following at the top
of your module

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Cheers
Shasur
 
M

MarkS

Thank you, although I think the file may have been created anyway, i.e a
FileName is given but not saved completely but I will put in a sleep to
ensure that the code does not fall all the way through prior to competing the
save
 
Top