By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,311 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,311 IT Pros & Developers. It's quick & easy.

Acrobat Distiller 6.0, VBA and MS Word

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Resolved. I kept moving it around until I found a spot -- AFTER I
close Word AND release the object. (Even though closing Word should
have been enough.)

-------------START OF SAMPLE CODE--------------

'Previously declared string variables
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"
LogFilename = "I:\RPS & REO\BPO's\" & Forms!frmBPOReview!Loan_Num &
"_" & Forms!frmBPOReview!Address & "_" & Forms!frmBPOReview!Borrower &
".log"

{snip -- other unrelated stuff here}

'Print to postscript/Distiller file
objWord.ActivePrinter = "Adobe PDF"
objWord.ActiveDocument.PrintOut printtofile:=True,
outputfilename:=PSFilename

{snip -- other unrelated stuff here}

'Close Word, do not save document
objWord.ActiveDocument.SaveAs DOCfilename
objWord.ActiveDocument.Close
If AppNotRunning = True Then
objWord.Quit
End If

{snip -- other unrelated stuff here}

Set objWord = Nothing

'Covert PS file to PDF and kill extra files that were generated
Dim AcroDist As New PdfDistiller6
AcroDist.FileToPDF PSFilename, PDFFilename, ""
Kill PSFilename
Kill LogFilename

PSFilename = ""
PDFFilename = ""
DOCfilename = ""
LogFilename = ""

-------------END OF SAMPLE CODE--------------
ni*****@namg.com (Nicole) wrote in message news:<7f*************************@posting.google.c om>...
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

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.