nathandavies
Member
- Outlook version
- Outlook 2010 64 bit
- Email Account
- Exchange Server
I have seen a thread this morning "Save Emails on Hard Drive" which interested me I was wondering if this code can be changed at all to complete the following?
1. When the macro is run a input box appears for a string of text to input the location of the folder on a server. IE Project Number
2. When the project number is inputted the macro will search through our server “P:\Group\JOBDATA” or “P:\Group\QUOTATION" and find the folder and save any incoming emails to a specific folder “Email.In” within the “Correspondence” Folder and “Email.Out” for outgoing emails.
I know this might be asking a lot but if anyone can help that would be greatly appreciated!!
Sub SaveMessages()
'Declaration
Dim myItems, myItem As Object
Dim myOrt As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim FindTerm(13)
'Set invalid characters to replace
FindTerm(0) = "*"
FindTerm(1) = "@"
FindTerm(2) = "\"
FindTerm(3) = "("
FindTerm(4) = ")"
FindTerm(5) = "["
FindTerm(6) = "]"
FindTerm(7) = "?"
FindTerm(8) = "<"
FindTerm(9) = ">"
FindTerm(10) = "!"
FindTerm(11) = "{"
FindTerm(12) = "}"
FindTerm(13) = ":"
'Ask for destination folder
myOrt = InputBox("Destination", "Save Attachments", "P:\")
On Error Resume Next
'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
'for all items do...
For Each myItem In myOlSel
strdate = myItem.SentOn
newdate = Format(strdate, "yyyymmddhhmm")
strname = newdate & "-" & myItem.Subject & ".msg"
For i = 1 To 13
newstr = Replace(strname, FindTerm(i), " ")
strname = newstr
Next
myItem.SaveAs myOrt & newstr
myItem.Delete
Next
'free variables
Set myItems = Nothing
Set myItem = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub
1. When the macro is run a input box appears for a string of text to input the location of the folder on a server. IE Project Number
2. When the project number is inputted the macro will search through our server “P:\Group\JOBDATA” or “P:\Group\QUOTATION" and find the folder and save any incoming emails to a specific folder “Email.In” within the “Correspondence” Folder and “Email.Out” for outgoing emails.
I know this might be asking a lot but if anyone can help that would be greatly appreciated!!
Sub SaveMessages()
'Declaration
Dim myItems, myItem As Object
Dim myOrt As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim FindTerm(13)
'Set invalid characters to replace
FindTerm(0) = "*"
FindTerm(1) = "@"
FindTerm(2) = "\"
FindTerm(3) = "("
FindTerm(4) = ")"
FindTerm(5) = "["
FindTerm(6) = "]"
FindTerm(7) = "?"
FindTerm(8) = "<"
FindTerm(9) = ">"
FindTerm(10) = "!"
FindTerm(11) = "{"
FindTerm(12) = "}"
FindTerm(13) = ":"
'Ask for destination folder
myOrt = InputBox("Destination", "Save Attachments", "P:\")
On Error Resume Next
'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
'for all items do...
For Each myItem In myOlSel
strdate = myItem.SentOn
newdate = Format(strdate, "yyyymmddhhmm")
strname = newdate & "-" & myItem.Subject & ".msg"
For i = 1 To 13
newstr = Replace(strname, FindTerm(i), " ")
strname = newstr
Next
myItem.SaveAs myOrt & newstr
myItem.Delete
Next
'free variables
Set myItems = Nothing
Set myItem = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub