Good afternoon.
I am having a bit of a problem that I can't quite figure out. Below is portion of my code which sends an email from an Excel macro:
Sub MailTest()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "a****@*****.com"
.CC = "a*****@*****.com"
.BCC = ""
.Subject = "Testicus Emailicus Minimus #2"
.BodyFormat = olFormatHTML
.HTMLBody = "<html><body><p>This is a paragraph.</p><p>This is a paragraph.</p><p>This is a paragraph.</p></body></html>"
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Now, this code works great if I run it directly from Excel. The problem arises when I call it from a VBScript, the relevant code is displayed below:
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Documents and Settings\*******\My Documents\nothing to see here.xlsm")
objExcel.Application.Run "'nothing to see here.xlsm'!MailTest()"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Echo "Finished."
WScript.Quit
When I run it from the VBScript, two emails are sent. I realize this isn't the biggest problem, but it is annoying and I'd like to know why. If anyone could help with this, that would be great!
Bookmarks