1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Hyperlink to specific .pdf page from Excel

Discussion in 'Business Applications' started by laguy83, Dec 22, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. laguy83

    laguy83 Thread Starter

    Joined:
    Dec 19, 2008
    Messages:
    32
    Hi All,

    I am trying to create a hyperlink in Excel that will open up a specific page from a .pdf file stored on a network drive. Unfortunately I am only able to get the pdf file to open to the first page. Any help would be greatly appreciated!!!!

    Thanks!
     
  2. WendyM

    WendyM Trusted Advisor

    Joined:
    Jun 27, 2003
    Messages:
    4,032
  3. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,447
    Wow! Nice Wendy!! I was trying to figure out how to do it via the Object Model. That's so simple!! Learn something new each day. :)
     
  4. laguy83

    laguy83 Thread Starter

    Joined:
    Dec 19, 2008
    Messages:
    32
    Thanks for your help, WendyM. Unfortunately, the problem I have is that the pdf file I am linking to is not online, but rather is stored on a local drive. For some odd reason Acrobat does not allow you to link to individual pages when the pdf file is stored on a local drive - only when it is stored online. Is there another solution, for locally-stored pdf files? Thanks so much.
     
  5. computerman29642

    computerman29642

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Give this code a try

    Code:
    Sub OpenPDFpage()
        Dim myLink As String
        Dim TargetPage As Double
        Dim objIE As New InternetExplorer
    
        [B]myLink = "path/filename.pdf"[/B] *Replace with your PDF path destination
        TargetPage = 7   'Page number to be shown
    
        With objIE
            .Navigate myLink & "#page=" & TargetPage
            .Visible = True
        End With
    End Sub
    
    This code was found at the link below:

    http://excel.tips.net/Pages/T003350_Linking_to_a_Specific_Page_in_a_PDF_File.html
     
  6. laguy83

    laguy83 Thread Starter

    Joined:
    Dec 19, 2008
    Messages:
    32
    Thank you so much for your help computerman. But at the risk of appearing like a total novice....i've never used code before. Can you tell me how exactly I go about using this code, or at least point me in the direction of an FAQ or tutorial or something? I'm good with computers but just have no training in code or macros....
     
  7. computerman29642

    computerman29642

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Do you want to run the code through a button, or by clicking on something in a cell?
     
  8. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,447
    CM, you're getting fast!! Was working on something, but ya beat me to it! Here it uses late binding though, no reference needed...

    Code:
    Sub TestPDFlink()
        Dim IE As Object, strFile As String, iPageNum As Long
        strFile = "C:\Users\Zack\Desktop\OpenPDF\Book1.pdf"
        iPageNum = 2
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Navigate strFile & "#Page=" & iPageNum
        IE.Visible = True
    End Sub
    Just copy/paste code into a standard module (Alt + F11, Alt + I, M).

    HTH
     
  9. laguy83

    laguy83 Thread Starter

    Joined:
    Dec 19, 2008
    Messages:
    32
    I would like to just click on a link in the cell and have it open up the pdf file...is that what you mean?
     
  10. computerman29642

    computerman29642

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Zack, you are the MAN!!! :D

    Can you explain what you mean by late binding?
     
  11. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,447
    You would need a button. The functionality of an inserted hyperlink doesn't give you what you want, but the VBA code does (hence the button). Or you could write more code to if you select that cell, or double click it, or whatever.
     
  12. computerman29642

    computerman29642

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Zack, I was actually working on the double-click option. :)
     
  13. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,447
    Yup. Late binding does not use references. Early binding does. VBE | Tools | References. All those listed are object models you can reference to your current project (whatever the active project is). Doing so will give you use of the object library and intellisense. When you see my code, I declared the variable as an Object, plus I used the CreateObject() call, which creates the object (if installed on the host computer). The code you had, you would've needed to go to Tools | References, then check the Microsoft Internet Controls control. Then you can use something like Dim IE as InternetExplorer, because traditionally it's not available to the Excel Object Model.

    I prefer late binding because it transports to any machine, no need to set references, sometimes references can come up missing if somebody doesn't have a full install, or just versioning you can come up with reference(s) issues. Early binding can be nice, if it is a solution which only you will run and the solution won't move around. If I'm posting to the board and I don't know that, generally I'll use late binding.

    Binding is just referring to how you are bound to an object (i.e. what object library you are referencing). Make sense?
     
  14. computerman29642

    computerman29642

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Thanks Zack. Yes, I believe I get what you are saying. If not, I know who to come and ask..LOL!
     
  15. laguy83

    laguy83 Thread Starter

    Joined:
    Dec 19, 2008
    Messages:
    32
    Thank you guys all so much. I really appreciate your efforts.

    Zack - I used the code you posted:

    Sub TestPDFlink()
    Dim IE As Object, strFile As String, iPageNum As Long
    strFile = "C:\Users\Zack\Desktop\OpenPDF\Book1.pdf"
    iPageNum = 2
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate strFile & "#Page=" & iPageNum
    IE.Visible = True
    End Sub

    However, although it does open up the pdf file, it still only takes me to the first page. Any idea how I can target a specific page?

    Thanks again!

    Brian
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/782235