Logan Price
Logan Price

Reputation: 121

VBA; Open PDF in existing PDF window (as a new tab)

I am trying to use VBA to open a PDF in an existing Adobe Acrobat window.

Currently, however, my code is opening the pdf in a separate Adobe window each time it is run.

End goal: VBA opens a PDF in an existing Adobe acrobat window in the form of a new PDF tab.

Here is my code:

Sub openPDF(sPath As String)

    Dim primaryDoc As Object, PrimaryAVDoc As Object, appAdobe As Object ' Open Adobe instance
    Dim zPath As String
    Dim adobeDoc As Variant, PDFPageView As Variant
    
    Set appAdobe = CreateObject("AcroExch.App")
    
    ' Create Adobe PDF object
    Set primaryDoc = CreateObject("AcroExch.PDDoc")
    
    Set PrimaryAVDoc = CreateObject("AcroExch.AVDoc")
    
    If PrimaryAVDoc.Open(sPath, "") = True Then
        PrimaryAVDoc.BringToFront
        Call PrimaryAVDoc.Maximize(True)
        Set PDFPageView = PrimaryAVDoc.GetAVPageView()
        ' Zoom (optional)
'        Call PDFPageView.ZoomTo(2, 50)
    End If
    
    Set primaryDoc = Nothing
    Set PrimaryAVDoc = Nothing
    Set appAdobe = Nothing
    
End Sub

Upvotes: 0

Views: 369

Answers (1)

K J
K J

Reputation: 11857

Whilst heavily used by programmable graphics applications, generally:-

This is a user application setting (depending on version user interface) it is unlikely to be externally program related (but see note below). Each user installation, just like in a browser, has user settings/preferences and this is thus a user run time option. I am not going to install every version or yours just to prove your user version does or does not have the required setting.

enter image description here

Many PDF viewers have legacy and Tabbed mode options (often addressable via DDE in Windows or Pipes in other systems) that may or may not be externally addressable for reuse windows. Those that are SyncTeX Aware usually have widest range of settings for external IDE calls. Adobe is SyncTeX Aware but offers fewer choices.

Here the upper quartiles setting is open as separate windows.
Lower view all files are now opened in tabs mode.

enter image description here

Upvotes: 0

Related Questions