Can't open pdf from user form

ALINCO

New Member
Joined
Dec 9, 2018
Messages
11
Help please. Since switching from 2010 to 2019 the command button to open a pdf returns "compile error: cant find project or library"
A txtbox is populated from a column after double clicking a component listed in the output box.
Click the cmdPDF button, in 2010, opened up the PDF. 2019 returns the above error.
I have copied and pasted both PDF_Dir and READERPath to an Explorer search bar and they lead to where they should.
I have not ruled out the possibility that the office upgrade coincided with a coding mistake some how.
Tried using XL2BB but Mini Sheet is ghosted out. Hope this is ok.




VBA Code:
Private Sub cmdPDF_Click()
Dim PDFDir As String, FName As String, PDFFile As String
Dim READERPath As String

FName = txtPDF
     If (txtPDF.Value) = "" Then
        MsgBox " Nothing to Open", vbCritical, "Error"
     Cancel = True
Exit Sub
End If
    PDF_Dir = "C:\Users\Dave\Desktop\Components_WIP\Components_PDFs\"
        PDFFile = PDF_Dir & FName & ".pdf"
            READERPath = "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
                Shell READERPath & " " & PDFFile, vbNormalFocus
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I suspect @Logit's point is that your code is unnecessarily complicated for what you're trying to accomplish. As Logit points out - ActiveWorkbook.FollowHyperlink (followed by the PDF file name) - will accomplish the same thing. The longer and more intricate the code, the more likely it is that something will go horribly wrong. I suspect that the issue with your code - and why it works when you enter the details manually, but it doesn't work when you try to do it programmatically - is probably due to the PDF viewer path... You'll note that there is a space in it (between 'Program' and 'Files') - when you pass a string like that to the Shell command, Shell won't know that it's in fact one argument (the full executable path) and not two arguments (separated by a space):- "C:\Program" and "Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe") - same again for FName and if the filename has something in it that would confuse Shell.

You can solve it by wrapping each argument in quotation marks.

That said, I'm not sure that this explains that particular error message, which is an odd one in the circumstances. I feel like there is an important piece of information missing here, but not quite sure what it could be. Anyway, let us know how it goes.
 
Upvote 0
I found the problem
Dim PDFDir
PDF_Dir =
Spot the difference!!!
Thanks anyway
That's why it's a good idea to add the Option Explicit statement at the top of any module. It forces the declaration of all variables, and at compile time it would have flagged PDF_Dir as not being declared, thereby catching the error.
 
Upvote 0
Update:
could edit and save in 2019 but when opening again in 2019 it froze on the green box and needed ctrl alt del to clear it. It works in 2010 however.
I reinstalled 2010 and it works fine with or without the underscores.
After editing the underscores out in 2010, and saving, it opened and worked perfectly with 2019
I hope this info is of use to others with similar Macro issues between versions.

I shall look at the option explicit option soon and the hyperlink option also
TY all!
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top