Save Attachment and insert hyperlink

G

Guest

Hello,
I am trying to write a macro so that the attachment is saved to a specific
folder and then a hyperlink is inserted to the saved document. From the help
I got the below code to save the first attachment and I also saw som code to
strip the email from the atchement but I couldn't find a way to insert a
hyperlink. I am new to Office VBA and would appreciate anykind of help.

Thanks,
Ozgur

Sub SaveAttachment()
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myOlApp = CreateObject("Outlook.Application")
Set myInspector = myOlApp.ActiveInspector
If Not TypeName(myInspector) = "Nothing" Then
If TypeName(myInspector.CurrentItem) = "MailItem" Then
Set myItem = myInspector.CurrentItem
Set myAttachments = myItem.Attachments
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the first attachment
in the current item to the C:\ folder? If a file with the same name already
exists in the destination folder, it will be overwritten with this copy of
the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
myAttachments.Item(1).SaveAsFile "L:\" & _
myAttachments.Item(1).DisplayName
End If
Else
MsgBox "The item is of the wrong type."
End If
End If
End Sub
 
G

Guest

You can add a "shortcut" to a file using the olByReference Type as an
argument in the Attachments.Add method:

objItem.Attachments.Add "C:\myfile.txt", OlAttachmentType.olByReference

For a true hyperlink though, just insert text into the message body using
the file:// protocol:

fiile://C:\myfile.txt

Both methods though presume the receiver has access to the file path, and
that the location doesn't change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top