Solved

Open embedded pdf file in word with one click through hyperlink

Posted on 2009-05-13
6
1,325 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
ID: 24386253
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
ID: 24387666
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
ID: 24389002
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Closing Comment

by:michael1174
ID: 31581173
thanks, great work!
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24416258
I'm so glad!  Thank you.

Joanne Orzech
MS Word MVP
EE Zone Advisor
0
 

Expert Comment

by:SciEditor
ID: 24705442
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
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…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

911 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

23 Experts available now in Live!

Get 1:1 Help Now