Saving an Outlook Item using VBA

Durlov

New Member
Joined
Feb 10, 2016
Messages
11
Hello all,

I'm having trouble saving the outlook item. (Hmmm, I just realized I'm working with Ms Word - does it matter? Can I still post here?) Anyways, the issue is that, Word is creating the Message and sending it just fine (with attachments, subject and everything), but it is not saving the file in the designated location properly. It is saving as 1 KB and not opening. Below is the code and an image of the error. Thanks much for your help!

Code:
Private Sub CommandButton1_Click()


Dim myString As String
Dim myString2 As String


Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)

' Doing some texts replacements here.
myString = Label9
myString = Replace(myString, "[Name of Person]", TextBoxNoP.Value)
myString = Replace(myString, "[Name of Establishment]", TextBoxNoE.Value)
myString = Replace(myString, "[Date Received]", TextBoxDR.Value)


myString2 = Label10
myString2 = Replace(myString2, "[Name of Establishment]", TextBoxNoE.Value)
myString2 = Replace(myString2, "[Date Received]", TextBoxDR.Value)

' Done with texts replacements here. Setting up, saving and sending messages.
Set myAttachments = myItem.Attachments
 
myItem.To = TextBoxTo.Value
myItem.CC = TextBoxCC.Value
myItem.Subject = myString2
myAttachments.Add "\\di-afs.doi-ad.state.nv.us\LifeHealth\Charitable Gift Annuities\Charitable Gift Annuities 2016\Pending Charitable Gift Annunites\" & TextBoxAtt.Value & ".pdf"
myItem.Body = myString
myItem.SaveAs "\\di-afs.doi-ad.state.nv.us\LifeHealth\Charitable Gift Annuities\Charitable Gift Annuities 2016\E-mails sent by Nanci\" & myString2 & ".msg", olMsg
myItem.Send




Unload Me


End Sub

Hmmm, I can't seem to attach an image from my PC (not seeing the option.) Anyhoo, the message basically says the file does not seem to exists, or cannot be open.

Thanks much for your help!!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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