Solved

Open embedded pdf file in word with one click through hyperlink

Posted on 2009-05-13
6
1,319 Views
Last Modified: 2012-05-06
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
Comment
Question by:michael1174
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
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
 
LVL 2

Author Comment

by:michael1174
Comment Utility
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
 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 500 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Author Closing Comment

by:michael1174
Comment Utility
thanks, great work!
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
I'm so glad!  Thank you.

Joanne Orzech
MS Word MVP
EE Zone Advisor
0
 

Expert Comment

by:SciEditor
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now