A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Save Attachment and insert hyperlink



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 5th 07, 12:26 PM posted to microsoft.public.outlook.program_vba
Ozgur Pars
external usenet poster
 
Posts: 1
Default Save Attachment and insert hyperlink

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
Ads
  #2  
Old February 5th 07, 04:49 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Save Attachment and insert hyperlink

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.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Ozgur Pars" wrote:

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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I insert a contact detail from a email attachment chilli hot Outlook - Using Contacts 1 October 29th 06 02:15 PM
vba code that insert a hyperlink file in the body of message gabriel Outlook and VBA 3 April 24th 06 01:51 PM
Shortcuts do not work when using Insert/File Attachment Millicent Outlook Express 10 March 14th 06 08:27 PM
Insert Attachment - default folder Cooler Dude Outlook Express 3 March 5th 06 10:13 AM
Insert a hyperlink to section of Word doc in an outlook message [email protected] Outlook - General Queries 0 February 8th 06 05:07 AM


All times are GMT +1. The time now is 07:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.