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

Saving attachemtns automatically



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 14th 07, 08:12 PM posted to microsoft.public.outlook.program_vba
Frank[_3_]
external usenet poster
 
Posts: 5
Default Saving attachemtns automatically

Hi,

I'm trying to implement a solution that saves all my attachments in a folder
automatically.
I found the code below that is a good start.

However, I have some questions:

1.) How can I make a simple method like the one below visible in the outlook
menu or toolbar?

2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how to
structure the script to receive the proper input value and execute SaveAs
only for this email

Any help would be appreciated.



Private Sub SaveAttachements()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next


End Sub


  #2  
Old November 14th 07, 08:21 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Saving attachemtns automatically

1) View | Toolbars | Customize, then drag your macro from the list of commands to the desired toolbar.

2) In the procedure for a "run a script" rule action, the item being processed is passed as an argument :


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

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
msg.Attachments(1).SaveAsFile some file name

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message ...
Hi,

I'm trying to implement a solution that saves all my attachments in a folder
automatically.
I found the code below that is a good start.

However, I have some questions:

1.) How can I make a simple method like the one below visible in the outlook
menu or toolbar?

2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how to
structure the script to receive the proper input value and execute SaveAs
only for this email

Any help would be appreciated.



Private Sub SaveAttachements()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next


End Sub


  #3  
Old November 14th 07, 08:42 PM posted to microsoft.public.outlook.program_vba
Frank[_3_]
external usenet poster
 
Posts: 5
Default Saving attachemtns automatically

Hi,

Thanks for the fast answers.

About 1.) How do I need to declare my Sub so that it shows up in the command
list?

A new question:
Is there a way to check the date of the attachment item? I would like to
overwrite older attachments.


"Sue Mosher [MVP-Outlook]" wrote in message
...
1) View | Toolbars | Customize, then drag your macro from the list of
commands to the desired toolbar.

2) In the procedure for a "run a script" rule action, the item being
processed is passed as an argument :


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

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
msg.Attachments(1).SaveAsFile some file name

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message
...
Hi,

I'm trying to implement a solution that saves all my attachments in a
folder
automatically.
I found the code below that is a good start.

However, I have some questions:

1.) How can I make a simple method like the one below visible in the
outlook
menu or toolbar?

2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how
to
structure the script to receive the proper input value and execute SaveAs
only for this email

Any help would be appreciated.



Private Sub SaveAttachements()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next


End Sub




  #4  
Old November 14th 07, 10:22 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Saving attachemtns automatically

1) As a macro, public with no arguments.

2) "Older" compared with what? You can work with the attachment itself only after it has been saved.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message ...
Hi,

Thanks for the fast answers.

About 1.) How do I need to declare my Sub so that it shows up in the command
list?

A new question:
Is there a way to check the date of the attachment item? I would like to
overwrite older attachments.


"Sue Mosher [MVP-Outlook]" wrote in message
...
1) View | Toolbars | Customize, then drag your macro from the list of
commands to the desired toolbar.

2) In the procedure for a "run a script" rule action, the item being
processed is passed as an argument :


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

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
msg.Attachments(1).SaveAsFile some file name

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message
...
Hi,

I'm trying to implement a solution that saves all my attachments in a
folder
automatically.
I found the code below that is a good start.

However, I have some questions:

1.) How can I make a simple method like the one below visible in the
outlook
menu or toolbar?

2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how
to
structure the script to receive the proper input value and execute SaveAs
only for this email

Any help would be appreciated.



Private Sub SaveAttachements()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next


End Sub




  #5  
Old November 15th 07, 03:52 PM posted to microsoft.public.outlook.program_vba
Frank[_3_]
external usenet poster
 
Posts: 5
Default Saving attachemtns automatically

Hi,

I got almost everything to work.

I would like to overwrite the file in my local folder only if the latest
attachment file is newer than the one already stored. Oftentimes, I receive
iterations of the same file name.

Currently, I'm using a randomizer:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objMessage.Attachments.Item(i).SaveAsFile "C:\mailarchive\attachments\" &
strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName

I would like to modify to:
IF mylocalfile.date attachement.date THEN
SaveAsFile




"Sue Mosher [MVP-Outlook]" wrote in message
...
1) As a macro, public with no arguments.

2) "Older" compared with what? You can work with the attachment itself only
after it has been saved.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message
...
Hi,

Thanks for the fast answers.

About 1.) How do I need to declare my Sub so that it shows up in the
command
list?

A new question:
Is there a way to check the date of the attachment item? I would like to
overwrite older attachments.


"Sue Mosher [MVP-Outlook]" wrote in message
...
1) View | Toolbars | Customize, then drag your macro from the list of
commands to the desired toolbar.

2) In the procedure for a "run a script" rule action, the item being
processed is passed as an argument :


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

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
msg.Attachments(1).SaveAsFile some file name

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message
...
Hi,

I'm trying to implement a solution that saves all my attachments in a
folder
automatically.
I found the code below that is a good start.

However, I have some questions:

1.) How can I make a simple method like the one below visible in the
outlook
menu or toolbar?

2.) I would like to run a "rule" and execute a script when I receive an
email with attachment. I know how to setup the rule. But I don't know how
to
structure the script to receive the proper input value and execute SaveAs
only for this email

Any help would be appreciated.



Private Sub SaveAttachements()

Const olFolderInbox = 6

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

For Each objMessage In colItems
intCount = objMessage.Attachments.Count
If intCount 0 Then
For i = 1 To intCount
strTempFile = objFSO.GetTempName
objMessage.Attachments.Item(i).SaveAsFile
"C:\mailarchive\attachments\" & strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName
Next
End If
Next


End Sub






  #6  
Old November 15th 07, 04:24 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Saving attachemtns automatically

An attachment in a mail message has no date properties. The only date information available would be the date properties associated with the parent message.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Frank" wrote in message ...
Hi,

I got almost everything to work.

I would like to overwrite the file in my local folder only if the latest
attachment file is newer than the one already stored. Oftentimes, I receive
iterations of the same file name.

Currently, I'm using a randomizer:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objMessage.Attachments.Item(i).SaveAsFile "C:\mailarchive\attachments\" &
strTempFile & "_" & _
objMessage.Attachments.Item(i).FileName

I would like to modify to:
IF mylocalfile.date attachement.date THEN
SaveAsFile

"Sue Mosher [MVP-Outlook]" wrote in message
...

2) "Older" compared with what? You can work with the attachment itself only
after it has been saved.

"Frank" wrote in message
...

A new question:
Is there a way to check the date of the attachment item? I would like to
overwrite older attachments.


 




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
Saving Photos B.W. Outlook Express 2 October 20th 07 06:32 AM
Stopping automatically saving email adresses to my contacts? [email protected] Outlook - Using Contacts 1 August 2nd 06 07:08 PM
Automatically saving attachments of a pst into windows folder Christian Goeller Outlook - General Queries 0 March 28th 06 10:23 AM
Saving Attachments [email protected] Add-ins for Outlook 0 January 11th 06 07:27 PM
Saving emails Daniel Outlook Express 3 January 9th 06 01:35 PM


All times are GMT +1. The time now is 05:06 AM.


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.