[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1367
  • Last Modified:

Open embedded pdf file in word with one click through hyperlink

Hi.  The following inserts a embedded pdf, creates a bookmark to it, and then adds a hyperlink to the bookmark.

What I need this code to do is once the hyperlink is opened, open the embedded pdf without having to goto the bookmark and double click on the embedded object.

Any ideas on how to go about doing this?  I'm open to any VBA code, or even .net to accomplish this.

Thanks...

Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.7", _
 FileName:="", LinkToFile:=False, DisplayAsIcon:=True, IconFileName:="C:\WINDOWS\Installer\{AC76BA86-7AD7-1033-7B44-A81200000003}\PDFFile_8.ico", IconIndex:=0, IconLabel:="AE02250693"
 
 ActiveDocument.Bookmarks.Add Name:="AE02250693", Range:=Selection.Range
 
 ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
  SubAddress:="AE02250693", ScreenTip:="", TextToDisplay:="AE02250693"
        
    If ActiveDocument.Bookmarks.Exists("AE02250693") = True Then
        ActiveDocument.Bookmarks.Item("AE02250693").Select
    End If

Open in new window

0
michael1174
Asked:
michael1174
  • 3
  • 2
1 Solution
 
Joanne M. OrzechManager, Document Services CenterCommented:
When I tested this, and simply went to the Edit menu, Acrobat Document Object, Open, I got the following code:

I think this should do it for you.
    Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary

Open in new window

0
 
michael1174Author Commented:
I tried but couldn't get it working.  To test out, I added a pdf to a word document, added a command button, and put that code in the command button.  When I click on the command button, nothing happens.

I even tried selecting the pdf object, and then clicking on the command button, but nothing happens.

Thanks for the help though.

Private Sub CommandButton1_Click()
 Selection.InlineShapes(0).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
End Sub

Open in new window

0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Here's the code I used which worked ... obviously, you'll need to change the network location -- no need to add a command button.  Just put it in your normal.dot and run by Alt-F8.

Sub Michael1174()
 
    Selection.InlineShapes.AddOLEObject ClassType:="AcroExch.Document.7", _
        FileName:= _
        "G:\WP\Instructions for outlook.pdf" _
        , LinkToFile:=False, DisplayAsIcon:=False
    Selection.HomeKey Unit:=wdStory
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="TestingOLE"
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
 
End Sub

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
michael1174Author Commented:
thanks, great work!
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
I'm so glad!  Thank you.

Joanne Orzech
MS Word MVP
EE Zone Advisor
0
 
SciEditorCommented:
I tried to create a macro using the code identified in the solution above (changing the pathname for the document I had embedded) and I get the following error:
Run-time error '5941':
The suggested member of the collection does not exist.

When I click Debug it shows the problem is in the following line of code:
Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary

This is my first attempt at using code, so I don't know what I might be doing wrong.  Also.. will this only work if I am embedding a pdf?  What if I am embedding a Word doc?

Thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now