gpt4 book ai didi

VBA 电子邮件签名代码证明

转载 作者:行者123 更新时间:2023-12-04 21:52:35 26 4
gpt4 key购买 nike

我对 VBA 还很陌生,我在编写一个宏来创建一个带有我的签名的电子邮件时遇到了麻烦。有人可以让我知道我的代码到底有什么问题以及如何修复它吗?

Sub SendFIleAsAttachment()

Dim OLApp As Outlook.Application
Dim OLMail As Object
signature As String

Set OLApp = New Outlook.Application
Set OLMail = OLApp.CreateItem(0)
OLApp.Session.Logon

With OLMail
.Display
End With
signature = OMail.Body
With OMail
.To = "email"
.CC = "email"
.BCC = ""
.Subject = "New Copy Proofing Request"
.Body = "body text. Thanks!" & vbNewLine & signature
.Attachments.Add ActiveWorkbook.FullName
End With
Set OLMail = Nothing
Set OLApp = Nothing
End Sub

最佳答案

您拼写错误 OLMailOMail你错过了Dim这个词一次在您的代码中。要修复此类语法错误,请遵循插入 Option Explicit 的良好做法。在您的模块/工作表顶部 - What do Option Strict and Option Explicit do?

Sub SendFIleAsAttachment()

Dim OLApp As Outlook.Application
Dim OLMail As Object
Dim signature As String

Set OLApp = New Outlook.Application
Set OLMail = OLApp.CreateItem(0)

With OLMail
.Display
End With
signature = OLMail.Body
With OLMail
.To = "email"
.CC = "email"
.BCC = ""
.Subject = "New Copy Proofing Request"
.Body = "body text. Thanks!" & vbNewLine & signature
End With

End Sub

关于VBA 电子邮件签名代码证明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51269534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com