[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Open embedded pdf file in word with one click through hyperlink

Posted on 2009-05-13
6
Medium Priority
?
1,363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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