opazzo
Board Regular
- Joined
- Dec 21, 2005
- Messages
- 69
- Office Version
- 365
- Platform
- Windows
Hi there,
I am trying to link certains cells from my excel worksheet to PDF Files. The trick is that those cells contains only a partial data string of the actual pdf file name.
To make things even worse the reference cell use a custom format so that the value entered is 01 but will look like 00001. The PDF file itself will be in the form of XXX-B-CCC-00001[and a lot of random stuff behind].pdf
I don't want to add new columns nor use hyperlinks (as much as possible). My preference would be to use macro with an on click event, so that when user click on cells the pdf file opens (similar to hyperlinks but withour hyperlinks).
I've looked through internet and came to copy and adjust the code below, which *kind of* work, EXCEPT that the file open inside the worksheet as text not as a pdf file in a new window .
I have the impression that I am not very far from my goal but would need a little help to go the next step and replace the Workbooks.OpenText function with something more suitable.
Thanks
----------------
Sub OpenCell()
Dim eMsg
Dim fName As String
Dim fPath As String
'set path to file: CHANGE TO SUIT
fPath = "My files\"
'handle oops
On Error GoTo oops
'get file name from cell
fName = ActiveCell.Value
fName = "XXX-B-CCC" & "*" & fName & "*"
Workbooks.OpenText FileName:=fPath & fName
oops:
eMsg = MsgBox("No such filename as " & fName & vbCrLf & "In Path " & fPath, vbExclamation)
End Sub
----------------
I am trying to link certains cells from my excel worksheet to PDF Files. The trick is that those cells contains only a partial data string of the actual pdf file name.
To make things even worse the reference cell use a custom format so that the value entered is 01 but will look like 00001. The PDF file itself will be in the form of XXX-B-CCC-00001[and a lot of random stuff behind].pdf
I don't want to add new columns nor use hyperlinks (as much as possible). My preference would be to use macro with an on click event, so that when user click on cells the pdf file opens (similar to hyperlinks but withour hyperlinks).
I've looked through internet and came to copy and adjust the code below, which *kind of* work, EXCEPT that the file open inside the worksheet as text not as a pdf file in a new window .
I have the impression that I am not very far from my goal but would need a little help to go the next step and replace the Workbooks.OpenText function with something more suitable.
Thanks
----------------
Sub OpenCell()
Dim eMsg
Dim fName As String
Dim fPath As String
'set path to file: CHANGE TO SUIT
fPath = "My files\"
'handle oops
On Error GoTo oops
'get file name from cell
fName = ActiveCell.Value
fName = "XXX-B-CCC" & "*" & fName & "*"
Workbooks.OpenText FileName:=fPath & fName
oops:
eMsg = MsgBox("No such filename as " & fName & vbCrLf & "In Path " & fPath, vbExclamation)
End Sub
----------------