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

How to save attachment automatically in Outlook 2003?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 9th 07, 10:42 PM posted to microsoft.public.outlook.program_vba
joannele71
external usenet poster
 
Posts: 6
Default How to save attachment automatically in Outlook 2003?

Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub

Ads
  #2  
Old March 10th 07, 04:20 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to save attachment automatically in Outlook 2003?

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments

etc.


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub

  #3  
Old March 15th 07, 01:54 PM posted to microsoft.public.outlook.program_vba
joannele71
external usenet poster
 
Posts: 6
Default How to save attachment automatically in Outlook 2003?

Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments

etc.


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub


  #4  
Old March 15th 07, 02:18 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to save attachment automatically in Outlook 2003?

What is the difference between "the real situation" and your tests?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments



"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub


  #5  
Old March 15th 07, 04:24 PM posted to microsoft.public.outlook.program_vba
joannele71
external usenet poster
 
Posts: 6
Default How to save attachment automatically in Outlook 2003?

I can't think of any differences except the emails are sending by someone
else and I may receive some other emails at the same time.

I receive the 3 emails daily and they come in one after they other within 2
minutes.

thanks

"Sue Mosher [MVP-Outlook]" wrote:

What is the difference between "the real situation" and your tests?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments



"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub



  #6  
Old March 29th 07, 08:02 PM posted to microsoft.public.outlook.program_vba
Jason B
external usenet poster
 
Posts: 3
Default How to save attachment automatically in Outlook 2003?

I have played around with this code a little bit and it seems to execute
within but it doesn't give a dialog bix where I can select a location and
file name nor can I find a directory where the attachments are being saved.
Is there a default location I am overlooking within the code?

"joannele71" wrote:

I can't think of any differences except the emails are sending by someone
else and I may receive some other emails at the same time.

I receive the 3 emails daily and they come in one after they other within 2
minutes.

thanks

"Sue Mosher [MVP-Outlook]" wrote:

What is the difference between "the real situation" and your tests?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments



"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub



  #7  
Old March 30th 07, 12:32 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to save attachment automatically in Outlook 2003?

Look at the SaveAs statement. Joannele71's original code uses C:\ as the hard-coded location/

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Jason B" wrote in message ...
I have played around with this code a little bit and it seems to execute
within but it doesn't give a dialog bix where I can select a location and
file name nor can I find a directory where the attachments are being saved.
Is there a default location I am overlooking within the code?


"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments


"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub



  #8  
Old March 30th 07, 02:38 AM posted to microsoft.public.outlook.program_vba
Jason B
external usenet poster
 
Posts: 3
Default How to save attachment automatically in Outlook 2003?

Upon re-reading the original post it appears that she is trying to save the
attachment only if it is from a particular person. I am not fluent in VB at
all for the most part, is there a way to cut out some of the parameters and
make this universal to all incoming emails?

"Sue Mosher [MVP-Outlook]" wrote:

Look at the SaveAs statement. Joannele71's original code uses C:\ as the hard-coded location/

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Jason B" wrote in message ...
I have played around with this code a little bit and it seems to execute
within but it doesn't give a dialog bix where I can select a location and
file name nor can I find a directory where the attachments are being saved.
Is there a default location I am overlooking within the code?


"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments


"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub




  #9  
Old March 30th 07, 03:44 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to save attachment automatically in Outlook 2003?

Her code is not a very good example of using a "run a script" rule to run code because it doesn't use the item that the procedure passes as an argument. This is a more correct structu

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' put code to process attachments here, e.g.
Debug.Print msg.Attachments.Count

Set msg = Nothing
Set olNS = Nothing
End Sub

These samples show various ways to save attachments that you could incorporate into the basic structure and run with no conditions:

http://www.fontstuff.com/outlook/oltut01.htm
http://www.outlookcode.com/codedetail.aspx?id=70
http://www.slovaktech.com/code_sampl...ripAttachments

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Jason B" wrote in message ...
Upon re-reading the original post it appears that she is trying to save the
attachment only if it is from a particular person. I am not fluent in VB at
all for the most part, is there a way to cut out some of the parameters and
make this universal to all incoming emails?

"Sue Mosher [MVP-Outlook]" wrote:

Look at the SaveAs statement. Joannele71's original code uses C:\ as the hard-coded location/

"Jason B" wrote in message ...
I have played around with this code a little bit and it seems to execute
within but it doesn't give a dialog bix where I can select a location and
file name nor can I find a directory where the attachments are being saved.
Is there a default location I am overlooking within the code?


"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments


"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If

End Sub




  #10  
Old April 5th 07, 08:56 PM posted to microsoft.public.outlook.program_vba
joannele71
external usenet poster
 
Posts: 6
Default How to save attachment automatically in Outlook 2003?

Hi Sue,

I am not fluent in VB either. Can you explain what is meant by "it doesn't
use the item that the procedure passes as an argument."? I am still trying
to fix my problem - the script doesn't work all the times.

Thanks

"Sue Mosher [MVP-Outlook]" wrote:

Her code is not a very good example of using a "run a script" rule to run code because it doesn't use the item that the procedure passes as an argument. This is a more correct structu

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' put code to process attachments here, e.g.
Debug.Print msg.Attachments.Count

Set msg = Nothing
Set olNS = Nothing
End Sub

These samples show various ways to save attachments that you could incorporate into the basic structure and run with no conditions:

http://www.fontstuff.com/outlook/oltut01.htm
http://www.outlookcode.com/codedetail.aspx?id=70
http://www.slovaktech.com/code_sampl...ripAttachments

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Jason B" wrote in message ...
Upon re-reading the original post it appears that she is trying to save the
attachment only if it is from a particular person. I am not fluent in VB at
all for the most part, is there a way to cut out some of the parameters and
make this universal to all incoming emails?

"Sue Mosher [MVP-Outlook]" wrote:

Look at the SaveAs statement. Joannele71's original code uses C:\ as the hard-coded location/

"Jason B" wrote in message ...
I have played around with this code a little bit and it seems to execute
within but it doesn't give a dialog bix where I can select a location and
file name nor can I find a directory where the attachments are being saved.
Is there a default location I am overlooking within the code?


"joannele71" wrote in message ...
Hi Sue,

Thank you for your help. After making the changes as per your suggestion,
it worked well when I did my testing. My testing was continuously sending 3
emails to myself and the script was able to save the attachment to the c:\.
However, I got the error message "rule operation failed" when it comes to the
real situation. Do you know what should I do? and why?

Thanks


"Sue Mosher [MVP-Outlook]" wrote:

The MailItem object that you should be working with is Item, the item passed as a parameter to the event handler, not myItem. You do not need to display it. Just work with its Attachments collection:

Set myAttachments = Item.Attachments


"joannele71" wrote in message ...
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.

Or if you have a better way to do this, please let me know.

Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Set myItem = Application.Session.GetDefaultFolder(olFolderInbox ).Items(1)
myItem.Display

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

myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
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
unable to save attachment-- Outlook 2003, C# Krishna Add-ins for Outlook 2 January 29th 07 06:54 PM
save attachment in calendar jvl_runner Outlook - Calandaring 1 January 22nd 07 02:21 PM
Automatically inserting the name of an attachment into the email t Montana Outlook and VBA 1 August 3rd 06 06:42 AM
How do I save an outlook calendar to send as an attachment? blancogato Outlook - Calandaring 1 August 1st 06 04:54 AM
Outlook 2003 needs save contact automatically when replying featur Missy Outlook - Using Contacts 5 June 6th 06 10:56 PM


All times are GMT +1. The time now is 10:06 PM.


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