Outlook 2010 Cannot get Macro to SAVE more than one message attachment???

geofferyh

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
The attached VBA macro works with Outlook 2010 Rules, saving the attachment in reservation messages that meet the condition of the rule. The macro saves an Excel .csv file attachment to a very specific location, that being: C:/MarinaPro/ResScheduler/.

Works well, for the first email, but not for any additional emails received. I simply can't get the macro to save more than one (1) attachment.

I am new to VBA and just cannot get this to work.

Help would be much appreciated.
 

Attachments

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Does the rule stop working or the code just not work?

Is some of the code missing? The inbox items macro doesn't have an end sub.
Public Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
If Item.Attachments.Count > 0 Then


While its doesn't matter, you don't need to split it with &:
strFolderpath = "C:\MarinaPro v18 Master\ResScheduler\"
 

geofferyh

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
The Outlook rule is working fine, and the macro (MP Macro.ThisOutlookSession.SaveAttachments) saves the attachment for the first email occurrence, but not for subsequent email occurrences found by the rule.

I will change to strFolderpath = "C:\MarinaPro v18 Master\ResScheduler\"

Save Reservation Attachment Rule.jpg
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Ok- one possible cause - you should only have 1 action in the rule. Either move the message using the rule and use an itemadd macro to save the attachment, or move it using the macro before or after you save it.
 

geofferyh

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Finally got a working macro and rule combination using a sample macro from Slipstick Systems and with some of my own modifications.

Only two problems remain to be solved, the renaming of the saved attachment formatted as strFile = DateFormat & "_" & TimeFormat & "_" & "CustLastNam.csv" being most problematic thus far.

The current code is:
' Get the file name.
strFile = objAttachments.Item(i).FileName

The wanted result is:
' Get the file name.
strFile = DateFormat & "_" & TimeFormat & "_" & "CustLastNam.csv" (but incremented)

I have tried several ideas, but can't seem to get "item(i)" to be formatted as wanted. Here is the current loop code:

If lngCount > 0 Then

For i = lngCount To 1 Step -1

' Get the Sent Date and Time
DateFormat = Format(Date, "MMddyy")
TimeFormat = Format(Time, "HHmm")

' Get the file name.
strFile = objAttachments.Item(i).FileName

' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile

' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile

Next i
End If

What am I missing here?
 

Attachments

geofferyh

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Final fix turned out to be quite simple.

Original script: strFile = objAttachments.Item(i).FileName

New script: strFile = Mid(objAttachments.Item(i).FileName, 12, 19) & "_CustLastNam.csv"

Chalk it up to the learning curve at my initiation into the world of VBA.
 

Attachments

Top