sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
I'm using the following code to open a message box to select a cell and then call up the "HyperlinkFile" macro directly below this one. Is there any easy way to make this code convert the e-mail to a ".pdf" file and saving it into the folder in the specified file path rather than the ".msg" file?
Sub CreateHyperLink()
Dim myReply As Range
On Error Resume Next
Set myReply = Application.InputBox(prompt:="Please select any cell", Type:=8)
If myReply Is Nothing Then Exit Sub
myReply.Activate
HyperlinkFile
End Sub
Sub HyperlinkFile()
Dim xGetFile As Object
Dim fName As String, sFullFilename As String, sFileName As String
'Opens dialog box to Pick File to Hyperlink
Set xGetFile = Application.FileDialog(msoFileDialogFilePicker)
With xGetFile
.Title = "Spreadsheet Creative - Select File to Hyperlink"
If .Show = -1 Then
'Selected File full path
fName = .SelectedItems(1)
Else
fName = ""
End If
End With
'Test if user pressed cancel
If fName = "" Then Exit Sub
'Resume code
'Get File name from path
sFullFilename = Right(fName, Len(fName) - InStrRev(fName, "\"))
On Error Resume Next
'Change display text to the Selected File name WITHOUT FILE EXTENSION
'if you want to display the file extension then change the formula from sFileName to sFullFilename
'sFileName = Left(sFullFilename, (InStr(sFullFilename, ".") - 1))
sFileName = ActiveCell.Text
On Error Resume Next
'Add HYPERLINK formula to active cell
ActiveCell.Formula = "=HYPERLINK(""" & fName & """,""" & sFileName & """)"
End Sub
Sub CreateHyperLink()
Dim myReply As Range
On Error Resume Next
Set myReply = Application.InputBox(prompt:="Please select any cell", Type:=8)
If myReply Is Nothing Then Exit Sub
myReply.Activate
HyperlinkFile
End Sub
Sub HyperlinkFile()
Dim xGetFile As Object
Dim fName As String, sFullFilename As String, sFileName As String
'Opens dialog box to Pick File to Hyperlink
Set xGetFile = Application.FileDialog(msoFileDialogFilePicker)
With xGetFile
.Title = "Spreadsheet Creative - Select File to Hyperlink"
If .Show = -1 Then
'Selected File full path
fName = .SelectedItems(1)
Else
fName = ""
End If
End With
'Test if user pressed cancel
If fName = "" Then Exit Sub
'Resume code
'Get File name from path
sFullFilename = Right(fName, Len(fName) - InStrRev(fName, "\"))
On Error Resume Next
'Change display text to the Selected File name WITHOUT FILE EXTENSION
'if you want to display the file extension then change the formula from sFileName to sFullFilename
'sFileName = Left(sFullFilename, (InStr(sFullFilename, ".") - 1))
sFileName = ActiveCell.Text
On Error Resume Next
'Add HYPERLINK formula to active cell
ActiveCell.Formula = "=HYPERLINK(""" & fName & """,""" & sFileName & """)"
End Sub