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
Solved

Open embedded pdf file in word with one click through hyperlink

Posted on 2009-05-13
6
1,331 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
C# Desktop Application 3 54
C# Gridview 1 45
Please explain purpose of GZIP 4 34
Paragraph formating? 2 23
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

809 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