0
這是我在記事本中保存的代碼。我是否需要更改Excel.Applications?VBA在記事本中運行Excel中的代碼錯誤
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 = "[email protected]"
Const strCC As String = "" '<~~ change "[email protected]" to "" if you do not want to CC
Const strBCC As String = "" '<~~ change "[email protected]" 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
發佈您的代碼以向我們展示您嘗試失敗的內容。 –
將宏放入Excel工作簿而不是記事本中。 – GolezTrol
這是在另一個woorkbook中控制宏的最簡單方法嗎? –