March 17, 2015

Automatically Open Specific Page in PDF Document Using Excel VBA

Many viewers wanted to know how to automatically open a specific page in a PDF document using Excel VBA. Watch the training video below before you study the complete VBA code and download the attached sample file:


Watch the video on YouTube.


Download a sample Excel file:


Complete VBA code for automatically opening a specific page number in a PDF document in Excel:
Sub openPDFPage()
Dim myLink As String
Dim myPage As Long
Dim objIE As New InternetExplorer

‘myLink = “C:\files-from-excelvbaonline\excel_vba_programming_for_dummies_3rd_edition.pdf”
myLink = “http://www.excelvbatutor.com/vba_book/vbabook_ed2.pdf”

myPage = InputBox(“Enter the page number”)

With objIE
.Navigate myLink & “#page=” & myPage
.Visible = True
End With
End Sub

6 thoughts on “Automatically Open Specific Page in PDF Document Using Excel VBA

  1. I enjoyed your video on how to convert excel to PDF file, and have it sent automatically. But how can I get selected area converted in the worksheet say “page-one”, “page-two” etc instead of the whole sheet?

  2. Hi Sir
    I have a list of the lecture notes and one pdf file that contain all the lecture notes in different page . I’ve used your recommendation and have assigned a macro to a button with this codes:

    Sub openPDFPage()
    Dim myLink As String
    Dim myPage As Long
    Dim objIE As New InternetExplorer

    myLink = “E:\Exam\MCCEE\internal.pdf”
    myPage = InputBox(“Enter the page number”)

    With objIE
    .Navigate myLink & “#page=” & myPage
    .Visible = True
    End With
    End Sub

    but after running the macro, Internet explorer opens the first page of my PDF file , not the page that I input there .
    I tried this format : E:\Exam\MCCEE\internal.pdf#page=23

    in the address bar of the Internet Explorer directly and it worked .
    of course after interring the address I have to refresh the address to go to my desire page (23)
    I need your Comment please.
    thank you very much

  3. Hi
    I have to add that I am using a Microsoft office 2013 in a Windows 10 based laptop

  4. Hi , I have a vba code to display pdf file in the web browser control when we click or select link from the listbox, its working fine with my pc but on another PC its automatically opening in “pdf adobe reader” instead of web browser. how can i change this to web browser? i cannot find the reason of this, please help!!

    Private Sub ListBox1_Click()
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    On Error Resume Next
    Dim AA1, AA2 As Variant
    AA1 = UserForm6.Frame1.ListBox1.Text
    AA2 = “C:\PO_Pfile\Temp1\Temp12.pdf”
    FileCopy AA1, AA2

    WebBrowser1.Navigate (AA1)
    Workbooks(“PO_SFile”).Sheets(“Sheet2”).Range(“AP2”) = AA1

    End Sub

  5. Hi! i tried your code and unfortunaly it doesn´t work, the variable declared as new InternetExplorer it is not recognized by the VBA, how can i fix it? Thanks a lot

    1. I am facing the same problem as Dr Takyar did not walk through the pdf file stage and went straight to IE. I couldn’t find the variable name to declare pdf object. I hope Dr can help us out on this. Thank you

Comments are closed.