Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook SaveAs with Attachment

Status
Not open for further replies.

Boots6

Technical User
Aug 12, 2011
91
US
Hello,

I have the following code that saves a message to our server with the Date/Time and Subject of the email then sends:

Sub SaveAs828()
Dim myItem As Outlook.Inspector
Dim objItem As Object
Dim EmailDate As Date
Dim MyMail As MailItem
Dim MailDate As String
On Error Resume Next
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
Set MyMail = myItem.CurrentItem
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
MailDate = Now()
MailDate = Replace(MailDate, "/", "-")
MailDate = Replace(MailDate, ":", ".")
strname = objItem.Subject
If strname <> vbNullString Then
objItem.SaveAs "C:\FILEPATH\" & MailDate & strname & ".msg", olMSG
Else
MsgBox "Please enter valid file name"
End If
End If

objItem.Send


End Sub

It works fine, but not when I attach files to the email. When I add attachments, it still sends, but does not save to the computer. It did before I added the Date and Time to the Document name. Help?

Thanks
 



What happens if you do it without the replace?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I don't know, but I'll give it a shot if it fails again. It just now started working again. I didn't change anything. It's bizarre. Of course it happened when I went to show someone...

Thanks for your response.
 
I figured it out it has something to do with the the Subject line of the email. If I just type in something like "ta" to do a test, it will give me the error "Please Enter Valid File Name." If I put a real word in the Subject line, like "The", it works. Are there rules behind this that I don't know about? Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top