UnsolvedCoding
Technical User
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?
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?