VBA Send Outlook email, Save email to file folder

melodramatic

Board Regular
Joined
Apr 28, 2003
Messages
187
Office Version
  1. 365
Platform
  1. Windows
I have tried looking up the answer to this, but somehow, I can't get this to work correctly.

I am having Excel send an email for me via vba, and after sending that email, save it to my project folder. And I obviously have not succeeded in finding the answer, as it's not working.

The Send portion is working just fine - the email goes out perfectly with the attachment. The only place where I'm having a problem is the SaveAs portion of it. It actually saved "a file" (with the correct name) to my folder, but when I tried to open the file, it came up as unreadable.

Hoping someone can give me a fix. I'm quite fine with it making me feel like I missed the obvious...

Thanks in advance!

Code:
            'Mail DCN to DocEmail
          
                Dim OutApp As Object
                Dim OutMail As Object
                Dim emailbody As String
                Dim convertbody As String
                Dim convertsubject As String
                Dim emailsubject As String
              
                Set OutApp = CreateObject("Outlook.Application")
                Set OutMail = OutApp.CreateItem(0)
              
                    On Error Resume Next
                    With OutMail
                        .To = DocEmail
                        .SentOnBehalfOfName = "DocCtrl@XXX.com"
                        .BCC = ""
                        .Subject = DCN
                        .Body = ""
                        .Attachments.Add (DocPath & DCN & ".pdf")
                        .SaveAs "X:\Document Control\PLCT Submittal\" & DCN & ".msg", 5 'THIS IS MY PROBLEM LINE THAT'S NOT WORKING
                        .Send
                    End With
                    On Error GoTo 0
          
                    Set OutMail = Nothing
                    Set OutApp = Nothing
                  
            ' END E-MAIL PORTION
          
LoopEnd:

    Next WorkLine
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Use 3 instead of 5 on the SaveAs line.

3 = olMSG - Outlook message format (.msg)
5 = olHTML - HTML format (.html)
 
Upvote 0
That worked fine, except now I realize I have gone a totally wrong route for this.

This saves the outlook file as a ready-to-send email. However, what I'm needing to put in my file folders is the proof of issue - in other words, a copy of the email as it appears in the Sent folder.

Hoping that I'm not being horrid with this, but can you help me with that route?
 
Upvote 0
One quick add-on note, I am using an Outlook rule to move all of the sent emails (for only this one type send) to a subfolder, Sent Items\Documents
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,977
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top