I'd like to open a specific PDF based on the file path in another sheet "Paths" cell C2, when I click a button (in another sheet) with a macro assigned.
I've just started learning vba last month so far I have this but I encounter an error -
Sub Sample()
ActiveWorkbook.FollowHyperlink Sheets("Paths").Range("C2")
End Sub
The error is:
Run-time error '-214722104 (800401ea)': Cannot open the specified file.
Please help.
CodePudding user response:
I think there is no error on the script. please check below points.
- Checking address of "sheets", "cells"
- Checking value of "C2" (as expected, the most likely) "C2" value like this C:\Users\aaa\Desktop\KR01.pdf
please check it.
CodePudding user response:
I just made this roundabout way to open the pdf ...
''' Sub OpenCIS()
Sheets("Paths").Select
Range("C3").Select
Selection.Copy
Dim x As Variant
Dim Path As String
' Set the Path variable equal to the path of your program's installation
Path = Sheets("Paths").Range("C2")
x = Shell(Path, vbNormalFocus)
Application.Wait Now 0.00002
Application.SendKeys "^{o}", True
Application.Wait Now 0.00002
Application.SendKeys "^{v}", True
Application.SendKeys "{HOME}", True
Application.SendKeys "{DEL}", True 'deletes the ? that appears before the path
Application.SendKeys "{ENTER}", True
End Sub ''' I don't know why the path appears as ?C:\Users\Renee Arianne\Desktop\Desktop - Filled CIS\CIS_2016 v5 filled.pdf.