phillipboles
asked on
VBA SaveAs and FolderDialog control
I am trying to make a simple VBA macro to achieve a simple repeatative task. We save email messages to a network share for later use or reference. The format of the email is title-date.msg and place in a particualar directory for each project. I am not able to figure out how to bring up a folder dialog so I can choose what folder to save the message too. Also, I get an error when trying to save the file with the date inserted. It saves fine if I remove the date from the path. So far I have come up with this code. I would like to have a form that would enable the user to add a prefix and suffix to the email title along with choosing the folder to save the item. Has anyone done this before?
Sub GetSelectedItems()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim MsgSender As String
Dim MsgSentOn As String
Dim MsgPath As String
Dim MsgDate As String
Dim x As Integer
MsgTxt = "You have selected items from: "
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & ";"
MsgSender = myOlSel.Item(x).Subject
MsgSentOn = myOlSel.Item(x).SentOn
MsgDate = Replace(MsgSentOn, "/", "-")
MsgPath = "C:\email\" & MsgSender & MsgDate & ".msg"
myOlSel.Item(x).SaveAs MsgPath, olMSG
Next x
MsgBox MsgTxt
End Sub
Thanks
Sub GetSelectedItems()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim MsgSender As String
Dim MsgSentOn As String
Dim MsgPath As String
Dim MsgDate As String
Dim x As Integer
MsgTxt = "You have selected items from: "
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgTxt = MsgTxt & myOlSel.Item(x).SenderName
MsgSender = myOlSel.Item(x).Subject
MsgSentOn = myOlSel.Item(x).SentOn
MsgDate = Replace(MsgSentOn, "/", "-")
MsgPath = "C:\email\" & MsgSender & MsgDate & ".msg"
myOlSel.Item(x).SaveAs MsgPath, olMSG
Next x
MsgBox MsgTxt
End Sub
Thanks
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.