Opening a PDF from an Excel User Form

V

Viswanath Tumu

I need to place a button on a User Form when clicked will
open a pdf file that is to be embedded into the main
file. I am able to do this in a regular spreadsheet by
inserting a 'package' object. The following code opens
the pdf from Excel.

Dim zx As Worksheet
Set zx = ThisWorkbook.Sheets("sheet1")

Application.DisplayAlerts = False
zx.Shapes("Object 2").Select
Selection.Verb Verb:=xlPrimary

However, this code is not working in an add-in. The line
that is generating an error is 'selection.verb'.

Is there a special tool in the control tool box that I
can use as a container for a pdf? Greatly appreciate any
help.
 
S

Steve Garman

Assuming that "sheet1" isn't in your add-in, try replacing
Set zx = ThisWorkbook.Sheets("sheet1")
with
Set zx = ActiveWorkbook.Sheets("sheet1")
 
G

Guest

Thanks! But this suggestion does not make any difference.
I have found a workaround as follows:

Since the code does not work only when a workbook is an
add-in, I added code at the start to set
the 'ThisWorkbook IsAddin' property to false.

Next, I run the original code, which now works fine,
since the workbook is not an add-in any more.

Finally, I rest the 'ThisWorkbook IsAddin' property to
True

To avoid displaying the worksheet in the background when
the workbook is not an add-in (for a very short period
only), I set the Application.screenupdating property to
false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top