Skip to main content
Kosta_stan
Inspiring
August 29, 2020
Answered

opening reader in excel VBA

  • August 29, 2020
  • 2 replies
  • 14826 views

I am trying for couple years to have an excel program that I have to be able to open a PDF file and go to a specific page.

There is a way if the file is a web-based file to open it via the excel using the IE (internet explorer).

But if the file is stored in local hard drive then IE cannot handle it.

So is any way using excel VBA to open a PDF file and go to a specific page using.

1-any other browsers.

2-any way to open it using Adobe Reader.

Any help on this will be much appreciated

Kosta

This topic has been closed for replies.
Correct answer Kosta_stan

"understand but Adobe reader is free for anyone to downloaded it’s allots of sites that offering to download free adobe reader." These sites are illegal, and are pursued by Adobe. Adobe want to strictly control all downloads. A download license (read the license) only allows you to install it for your own personal use.

 

"But besides that, which string you are referring." The string you pass on the shell command at the end of your code. That exact, complete string. Change the code to put it on the clipboard, or write it, then screen shot. We need to know exactly what it is: DO NOT retype what you think it is. 

 

 


I did that and is working.

And I found where was my mistake and I fix it and now works my way.

I cannot thank you enough about this.

Thank you,

Kosta

2 replies

Participant
August 29, 2020

Ok tnks

Kosta_stan
Inspiring
August 30, 2020

the excel file is in the Dropbox link below.

https://www.dropbox.com/s/p0m4jmwqvilhuay/test1%20PDF.xlsm?dl=0

the idea is to open the pdf file to a specify page and the page number are in column "E" I am not using the button in front page ruining the code directly from VBA this is work in progress.

As you see the code above, I am trying to open the file using IE and is tagging the page number in the end but IE omits that part of it even if you hard coded

Let me know please.

thank you

Kosta

Sub OpenPDFpage1()
    Dim myLink As String
    Dim mypage As Long
    If ActiveWindow.RangeSelection.Count > 1 Then
        MsgBox "Please select one cell in column E, then try again."
        Exit Sub
    End If
    If ActiveWindow.RangeSelection.Column <> 5 Then
        MsgBox "Please select one cell in column E, then try again."
        Exit Sub
    End If
    If Not IsNumeric(ActiveWindow.RangeSelection.Value) Then
        MsgBox "The active cell does not contain a page number."
        Exit Sub
    End If
    myLink = "D:\Dropbox\LIJSL Division Alignment\division alignment Fall 2020\" & _
        Range("B12").Value & "-" & "Registration Forms\" & Range("B12").Value & "-" & _
        Range("B9").Value & " " & Range("B10").Value & " " & Range("B11").Value & " " & _
        Range("D11").Value & ".pdf"
    mypage = ActiveWindow.RangeSelection.Value
    Shell "Acrobat.exe /A ""page=" & mypage & "=OpenActions"" """ & myLink & """", vbNormalFocus
End Sub

Legend
August 30, 2020

Since your problem is that your command line is invalid somehow you need to get the command line itself. I suggest you take the string you put on Shell and instead take the IDENTICAL string and copy it to the clipboard. Now you can paste it into a message to be examined. 

 

The most obvious possible problems are

1. You said you have Reader but have used the command line for Acrobat. Put the path name for Reader or Acrobat according to what the user has installed.

2. Both the executable name and the PDF file name need to be in quotes (like "c:\this\that file.pdf") if they have spaces in.

Legend
August 29, 2020

You can do it via the command line. https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDFOpenParameters.pdf

Very limited since, if the document is already open, it does nothing. To change the displayed page you can use OLE and JavaScript, but this needs paid-for Acrobat.

Kosta_stan
Inspiring
August 29, 2020

Thank you for your prompt replay,

This does not help me.

I was hoping that I can open a PDF file and the go to a specific page.

I need the command lines in VBA to do that.

Directing the VBA to open the PDF file using if need to be a acrobat reader that is stored in a specific directory and then go and open the file and go to a specify page.

I am very sure this is done before it is unthinkable that no one thought of this.

If I am in the wrong forum, please let me know witch forum I should be.

Thank you

Kosta

Legend
August 29, 2020

"This does not help me.

I was hoping that I can open a PDF file and the go to a specific page.

I need the command lines in VBA to do that."

You mean, like it explains on page 5??