• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help opening pdf through Excel using Visual Basic

cheezmunky

Senior member
I'm trying to open a pdf to a certain page by clicking on a link in Excel. For some reason the #page=* command doesn't work for hyperlinks through Excel.
I'm currently using some visual basic code I found online, and I've managed to get the pdf to open in an ie window after double-clicking on a cell. Everything is working fine except now the end user would like the links to open in the same window and not create a new window every time they're clicked. I'm completely new to visual basic, and don't have much experience with programming in general. Is there an easy way to accomplish this? Here is the code that I'm using right now:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Call PDFfile
End Sub

Sub PDFfile()
    Dim myLink As String
    Dim TargetPage As Double
    Dim IE As Object
    
    myLink = "c:\file.pdf"
    
    If ActiveCell.Column = 3 Then
        TargetPage = ActiveCell.Offset(0, -2)
        If ActiveCell.Offset(0, -2) <> "" Then
            Set IE = CreateObject("InternetExplorer.Application")
            IE.Navigate myLink & "#page=" & TargetPage
            IE.Visible = True
        End If
    ElseIf ActiveCell.Column = 4 Then
        TargetPage = ActiveCell.Offset(0, -3)
        If ActiveCell.Offset(0, -3) <> "" Then
            Set IE = CreateObject("InternetExplorer.Application")
            IE.Navigate myLink & "#page=" & TargetPage
            IE.Visible = True
        End If
    End If
End Sub

Thanks!
 
Back
Top