Open embedded PDF and bring that file to front

bisel

Board Regular
Joined
Jan 4, 2010
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Greetings all,

I have an Excel workbook with an embedded PDF.

I have created a macro that will open that PDF (see below).

VBA Code:
Sub getstarted()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    On Error Resume Next
    Sheet5.OLEObjects("getting_started").Verb xlVerbOpen ' Open the PDF file embedded in Sheet5
    Application.DisplayAlerts = True
    Sheet16.Activate ' Force return to Sheet16
  
End Sub

The problem I am having is that the macro is initiated from a single worksheet in the Excel workbook, but the embedded file is on a different worksheet which is normally hidden. Sometimes the PDF opens and the file is brought to the foreground as I would like. Sometimes, the macro opens the PDF but the file is the background.

I would like to force it to the foreground if I can.

Appreciate any help.

Regards,

Steve
 
Is it possible to post the revised code that you're currently using?
One issue that I have is that the workbook is distributed to several people. Some may have the 32-bit version of Adobe Reader and some may have the 64-bit version. So I thought I would merely use the, On Error Resume Next statement to move on regardless of which version of Reader the user has.

Here is the VBA ...

VBA Code:
Sub getstarted()

' If any error resume next.  Need this in case user does not have the 32Bit or 64Bit version of Adobe Reader
'    On Error Resume Next
   
    Sheet5.OLEObjects("getting_started").Verb Verb:=xlVerbOpen
    Sheet16.Select
   
' Use AppActivate to bring Acrobat Reader to the front, make sure to trap the error if user does not specific version of reader
'      AppActivate "Adobe Acrobat Reader DC(64-bit)"
     AppActivate "Adobe Acrobat Reader DC(32-bit)"
   
End Sub

To Test the AppActivate, I turned off the error trap, but I then get this error ...

1658627503179.png


This is what happens when I run the macro
  • The embedded PDF file opens
  • The error is displayed
If I capture the error with Resume Next, no error code is generated and the PDF opens, but the AppActivate statement does nothing.

Also, if I try run the macro immediately after closing the PDF, the PDF does not open. I have to wait a short period (e.g., 5 or 6 secs), before the macro functions again.

Very strange.

Steve
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
It looks like in both cases you're missing a space between "DC" and "(xx-bit)". So it should be...

VBA Code:
AppActivate "Adobe Acrobat Reader DC (32-bit)"

and

VBA Code:
AppActivate "Adobe Acrobat Reader DC (64-bit)"

However, to activate either the 32-bit version or the 64-bit version, try...

VBA Code:
    On Error Resume Next
    AppActivate "Adobe Acrobat Reader DC (32-bit)"
    AppActivate "Adobe Acrobat Reader DC (64-bit)"
    On Error GoTo 0

Hope this helps!
 
Upvote 0
It looks like in both cases you're missing a space between "DC" and "(xx-bit)". So it should be...

VBA Code:
AppActivate "Adobe Acrobat Reader DC (32-bit)"

and

VBA Code:
AppActivate "Adobe Acrobat Reader DC (64-bit)"

However, to activate either the 32-bit version or the 64-bit version, try...

VBA Code:
    On Error Resume Next
    AppActivate "Adobe Acrobat Reader DC (32-bit)"
    AppActivate "Adobe Acrobat Reader DC (64-bit)"
    On Error GoTo 0

Hope this helps!
Thanks. Added the space and that resolves the error.

Strange thing is occurring. If I initiate the macro, it opens the embedded PDF ... no issue. But if I try to initiate the macro immediately after closing the PDF window, nothing happens. I have to wait 3 to 5 seconds and then initiating the macro it then runs fine.

I have three different macros ... all the same structure ... that open an embedded PDF. The only difference between the macros is the name of the document. Here is the VBA that I am using ...

VBA Code:
Sub getstarted()

   
' If any error resume next.  Need this in case user does not have the 32Bit or 64Bit version of Adobe Reader
On Error Resume Next
   
    Sheet5.OLEObjects("getting_started").Verb Verb:=xlVerbOpen
    Sheet16.Select
   
' Use AppActivate to bring Acrobat Reader to the front, make sure to trap the error if user does not specific version of reader
    AppActivate "Adobe Acrobat Reader DC (64-bit)", True
    AppActivate "Adobe Acrobat Reader DC (32-bit)", True
   
On Error GoTo 0
   
End Sub

Everything now running OK, but there is this requirement to wait a few seconds before trying to run the macro again ... or run the same macro except for the document name.

I do not believe it is the AppActivate statement because if I comment those out, I get same symptom without them. So it must be in the OLEObjects open statement.

Thanks,

Steve
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top