Like many before me, I am tearing my hair out trying to get Acrobat
6.0 to work with VBA. I am getting close, and the error I am getting
now seems like it should be easy to surmount. So why am I stumped?!
;)
This code is in the middle of a large module in an ADP that takes web
data and ports it to an MS Word form that is dynamically generated
based on the data. Near the end, the Word doc needs to print to PDF
and save both the Word doc and PDF file. I have a working version of
this with Acrobat 4.0 using PDFWriter, but it doesn't work with later
versions of Acrobat and it's past time to upgrade.
Here's a snippet of the code in question (watch the word wrap):
----------------BEGINNING OF CODE----------------
'These three items are string variables, already declared.
'These set the file names instead of making the user type them
'and possibly store them in the wrong place or with the wrong name.
PSfilename = "I:\RPS & REO\BPO's\" & Forms!frmBPOReview!Loan_Num & "_"
& Forms!frmBPOReview!Address & "_" & Forms!frmBPOReview!Borrower &
".ps"
DOCfilename = "I:\RPS & REO\BPO's\Word\" & Forms!frmBPOReview!Loan_Num
& "_" & Forms!frmBPOReview!Address & "_" & Forms!frmBPOReview!Borrower
& ".doc"
PDFfilename = "I:\RPS & REO\BPO's\" & Forms!frmBPOReview!Loan_Num &
"_" & Forms!frmBPOReview!Address & "_" & Forms!frmBPOReview!Borrower &
".pdf"
'Here it calls an external procedure that captures the name
'of the user's default printer so it can be restored afterwards.
'Otherwise their Acrobat driver becomes the default
lpReturnedString = String(100, " ")
'Get the default printer from the win.ini file, application name =
[windows], key name = device
Call GetProfileString("windows", "device", "", lpReturnedString,
Len(lpReturnedString))
'GetDefaultPrinter = lpReturnedString
printer = lpReturnedString
'Print to Postscript/Distiller file
Dim AcroDist As New PdfDistiller6
objWord.ActiveDocument.PrintOut printtofile:=True,
outputfilename:=PSfilename
'Here's where it stops working. I need to convert the file to PDF
'and kill the postscript file
'I'll probably need to add something to kill the log file, too.
'It tries to run the code, but I get an error message
'stating that another process has locked the file.
AcroDist.FileToPDF PSfilename, PDFfilename, ""
Kill PSfilename
'Reset default printer
Call SetDefaultPrinter(printer)
'Close Word, do not save document
objWord.ActiveDocument.SaveAs DOCfilename
objWord.ActiveDocument.Close
If AppNotRunning = True Then
objWord.Quit
End If
----------------END OF CODE----------------
As the code notes state above, Distiller tries to covert the PS file
to PDF, but it can't continue because a process has it locked, and I
don't know why or which process. I have tried saving and closing Word
before making the PDF conversion, but that didn't help.
Any help would be appreciated.
Nicole