Cakz Primz
Board Regular
- Joined
- Dec 4, 2016
- Messages
- 102
- Office Version
- 365
- Platform
- Windows
Dear all,
I have cell value in cell K3 "TEP-TGH-MRR-CI-00460" based on this cell value, I would like to open a pdf file in certain folder only if the pdf file name start with K3 cell value.
The code below was found in internet, and it works ONLY if the pdf file name is exactly the same with K3 cell value.
How can I open the pdf file if the pdf file name started with cell K3 value?
Thank you very much in advance.
prima - Indonesia
I have cell value in cell K3 "TEP-TGH-MRR-CI-00460" based on this cell value, I would like to open a pdf file in certain folder only if the pdf file name start with K3 cell value.
The code below was found in internet, and it works ONLY if the pdf file name is exactly the same with K3 cell value.
How can I open the pdf file if the pdf file name started with cell K3 value?
VBA Code:
Sub OpenPDF()
' Declare variables
Dim filePath As String
Dim cellValue As String
' Get the value of the cell
cellValue = Range("K3").Value
' Specify the folder path
filePath = "C:\"
'filePath = "P:\7.LOG&MATERIAL\MATERIAL CONTROL\06-Warehousing\00 -Document Register\02 FINAL DOCUMENT\03-MRR\"
' Construct the full file path
filePath = filePath & cellValue & ".pdf"
' Check if the file exists
If Dir(filePath) = "" Then
MsgBox "The file " & cellValue & ".pdf" & " does not exist in the folder."
Else
' Open the file
ActiveWorkbook.FollowHyperlink filePath
End If
End Sub
Thank you very much in advance.
prima - Indonesia