• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

CreateObject("acroexch.pddoc") fails when another PDF is open

New Here ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

Have simple VBA function to determine wheather a pdf is 8x11 or not.

If there are no other PDFs open, function runs without error.

If another PDF is open the CreateObject("acroexch.pddoc") Fails.

Error Number: -2146959355

Error Description: Server execution failed

Code:

ublic Function funGetPdfPageSize(ByVal strAbsFName As String) As Boolean
On Error GoTo Err_Handler
Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc
Dim pdfPage As Object
Dim strFunName As String, strErrMsg As String
Dim width As Double
Dim height As Double
strFunName = "funGetPdfPageSize"
funGetPdfPageSize = False

If LCase(right(strAbsFName, 3)) <> "pdf" Then Err.Raise 65000, , "The input file is not a PDF file!"
'Set gApp = CreateObject("acroexch.app")
Set gPDDoc = CreateObject("acroexch.pddoc")
If gPDDoc.Open(strAbsFName) Then
Set pdfPage = gPDDoc.AcquirePage(0).GetSize()
height = pdfPage.Y / 72
width = pdfPage.x / 72
'Debug.Print width
'Debug.Print height
 If height <> 11 Or width <> 8.5 Then
     If height <> 8.5 Or width <> 11 Then
        Err.Raise 65000, , "Page size of PDF needs to be 8.5 X 11. Please print and scan to yourself."
     End If
 End If
End If
funGetPdfPageSize = True
Exit_Proc:
'Set gApp = Nothing
Set gPDDoc = Nothing
Set pdfPage = Nothing
Exit Function
Err_Handler:
strErrMsg = "The following error has occurred in " & strFunName & "." & vbCrLf
strErrMsg = strErrMsg & "Error Number: " & Err.Number & vbCrLf
strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrLf
strErrMsg = strErrMsg & "Error Source: " & Err.Source & vbCrLf
strErrMsg = strErrMsg & "Last DLL Error: " & Err.LastDllError & vbCrLf
strErrMsg = strErrMsg & "Help Context: " & Err.HelpContext & vbCrLf
strErrMsg = strErrMsg & "Help File: " & Err.HelpFile & vbCrLf
MsgBox strErrMsg
Resume Exit_Proc
End Function

 

Adobe acrobat standard DC

Continuous release version 2021.011.20039

 

 

TOPICS
Windows

Views

62

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

One thing to check: make sure Protected Mode is OFF (Enhanced Security preferences).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 27, 2022 Jun 27, 2022

Copy link to clipboard

Copied

LATEST

Unchecked Protected mode and issue persists, sorry did not mention that on original post.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines