これはメモ帳に保存したコードです。Excel.Applications を変更する必要がありますか?
Option Explicit
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("H:\shane.xlsm", 0, True)
xlApp.Run "Email"
xlBook.close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = nothing
これは、メールを送信する必要があるコードです。テストすると、正常に動作し、メールが送信されます。
Option Explicit
Const strTo As String = "dvandervieren@enerplus.com"
Const strCC As String = "" '<~~ change "def@abc.com" to "" if you do not want to CC
Const strBCC As String = "" '<~~ change "ghi@abc.com" to "" if you do not want to BCC
Sub Email()
Dim OutApp As Object, OutMail As Object
Dim strbody As String, strSubject As String
strSubject = "Hello World"
strbody = "This is the message for the body"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = "This is the Subject line"
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub