Ruben David
Member
- Outlook version
- Outlook 2013 32 bit
- Email Account
- Exchange Server
I have a script in place:
Private Declare Sub AppSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Sub PauseApp(PauseInSeconds As Long)
Call AppSleep(PauseInSeconds * 1000)
End Sub
Public Sub saveAttachtoDisk(Item As Outlook.MailItem)
Dim saveFolder As String
saveFolder = "c:\InvItems"
Dim dateFormat
dateFormat = Format(Now, "mmddyyyy-Hmmss")
Dim Subject As Variant
Subject = Item.Subject
Dim objAtt As Outlook.Attachment
For Each objAtt In Item.Attachments
objAtt.SaveAsFile saveFolder & "\" & Subject & "-" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Next
PauseApp 3
End Sub
The emails that come to me all have the pretty much the same subject name (Inv Report date of report etc...) the only difference is some come as .xml, xls, and doc.
The .xml files have a very long filename and it can't be changed when it sends to me so I tried to adapt to this by testing this code:
Private Declare Sub AppSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Sub PauseApp(PauseInSeconds As Long)
Call AppSleep(PauseInSeconds * 1000)
End Sub
Public Sub saveAttachtoDisk(Item As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
Dim Subject As Variant
Dim strFileExtension As String
saveFolder = "c:\InvItems"
dateFormat = Format(Now, "mmddyyyy-Hmmss")
Subject = Item.Subject
For Each objAtt In Item.Attachments
If InStr(objAtt.DisplayName, ".xml") Then
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
End If
Set objAtt = Nothing
Next
PauseApp 1
End Sub
This works but when I try to add additional code for the other file types to save with subject & date attached it doesn't work. I only want the .xml files to save as the filename but the other file types I need to keep the subject. I can use the first script and I get all the files save to my drive but the .xml files are not saving. I'm thinking it's because the filename is already long and I can't change this because another script picks up the files based on the subject name. The reason it worked before is because the .xml files weren't in the loop but now I get 15 of them a day that I need to save as well.
This is a rule not a macro because the plan is to have it running on a separate pc when I get this finalized.
Help me Obi Wan you're my only hope.
Private Declare Sub AppSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Sub PauseApp(PauseInSeconds As Long)
Call AppSleep(PauseInSeconds * 1000)
End Sub
Public Sub saveAttachtoDisk(Item As Outlook.MailItem)
Dim saveFolder As String
saveFolder = "c:\InvItems"
Dim dateFormat
dateFormat = Format(Now, "mmddyyyy-Hmmss")
Dim Subject As Variant
Subject = Item.Subject
Dim objAtt As Outlook.Attachment
For Each objAtt In Item.Attachments
objAtt.SaveAsFile saveFolder & "\" & Subject & "-" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Next
PauseApp 3
End Sub
The emails that come to me all have the pretty much the same subject name (Inv Report date of report etc...) the only difference is some come as .xml, xls, and doc.
The .xml files have a very long filename and it can't be changed when it sends to me so I tried to adapt to this by testing this code:
Private Declare Sub AppSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Public Sub PauseApp(PauseInSeconds As Long)
Call AppSleep(PauseInSeconds * 1000)
End Sub
Public Sub saveAttachtoDisk(Item As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
Dim Subject As Variant
Dim strFileExtension As String
saveFolder = "c:\InvItems"
dateFormat = Format(Now, "mmddyyyy-Hmmss")
Subject = Item.Subject
For Each objAtt In Item.Attachments
If InStr(objAtt.DisplayName, ".xml") Then
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
End If
Set objAtt = Nothing
Next
PauseApp 1
End Sub
This works but when I try to add additional code for the other file types to save with subject & date attached it doesn't work. I only want the .xml files to save as the filename but the other file types I need to keep the subject. I can use the first script and I get all the files save to my drive but the .xml files are not saving. I'm thinking it's because the filename is already long and I can't change this because another script picks up the files based on the subject name. The reason it worked before is because the .xml files weren't in the loop but now I get 15 of them a day that I need to save as well.
This is a rule not a macro because the plan is to have it running on a separate pc when I get this finalized.
Help me Obi Wan you're my only hope.