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

PDF conversion fails 1

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
I am baffled and hope someone knows the answer. I am running the code below and consistantly get the error that the server threw an exception. Typically at the line that reads Call AVDoc.Open(FilePath & FileName, "")

fso is declared as public in a different sub as Set fso = CreateObject("Scripting.FileSystemObject") and Warning_Flag is a byte declared as public from a different module.

The sub works in a different workbook using Adobe 6.0 Type Library.

Since 6.0 isn't in my version of excel referneces are set to Adobe Acrobat 9.0 Type Library and AdobePDFMakerX.

Sub ConvertToPDF()

' Just in case
On Error GoTo Error_Handler

Dim FileName As String
Dim FilePath As String

Dim AcroApp As CAcroApp
Dim AVDoc As CAcroAVDoc
Dim PDDoc As CAcroPDDoc

' Here for testing
FilePath = "C:\P_Temp_Folder\Temp_Files\"
FileName = "07714023.TIF"

'create obj
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")

'open non pdf file
Call AVDoc.Open(FilePath & FileName, "")

'set file obj
Set AVDoc = AcroApp.GetActiveDoc

If AVDoc.IsValid Then

Set PDDoc = AVDoc.GetPDDoc

If PDDoc.Save(1, FilePath & Left(FileName, Len(FileName) - 4) & ".pdf") <> True Then
MsgBox "Failed to save " & Left(FileName, Len(FileName) - 4) & ".pdf"
End If

PDDoc.Close

End If


'***************************************************
' Deletes sNewFileName .TIF
fso.deletefile sNewFileName
'***************************************************

'Closeup and cleanup
AVDoc.Close True
AcroApp.Exit
Set PDDoc = Nothing
Set AVDoc = Nothing
Set AcroApp = Nothing

' Bye-bye
Exit Sub

Error_Handler:

'Closeup and cleanup
AVDoc.Close True
AcroApp.Exit
Set PDDoc = Nothing
Set AVDoc = Nothing
Set AcroApp = Nothing

'Tell the user what went wrong
Application.StatusBar = "ConvertToPDF failed. " & Err.Description

' Set flag to indicate problem
Warning_Flag = 1

End Sub


Ideas?
 

hi,
fso is declared as public in a different sub
This cannot be done in a sub! This can ONLY be declared as PUBLIC in a MODULE in General Declarations.

BTW, use Option Explicit and avoid guessing at your errors.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


So if you step thru your procedure, what do you see?

faq707-4594

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
We finally got this figured out - stepping through the code didn't show anything wrong so things were escalated.

After a handful of us disecting this we discovered that the problem had to do with the references and a corrupted DLL. We made a few code changes to account for a few different things in our error handling and then replaced the corrupted files and things are going smoothly now.

Thanks much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top