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

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

  1. Ibrahim Idowu

    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?

    Reply
  2. FARAMARZ KORD

    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

    Reply
  3. Joby

    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

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *