简体   繁体   English

VBA在Windows 10上从用户窗体发送带有文本框的邮件作为正文内容

[英]VBA Send Mail with TextBox from userform as body content on Windows 10

I've been using the code below without any problems for a while now. 我使用下面的代码已有一段时间了,没有任何问题。 I have a Powerpoint slide, that when clicked opens a UserForm. 我有一张Powerpoint幻灯片,单击该幻灯片会打开一个用户窗体。 That userform contains a button, named SendMail, and a TextBox. 该用户窗体包含一个名为SendMail的按钮和一个TextBox。

the user insert comments into the Textbox, clicks SendMail and I get his comments in my e-mail box. 用户在文本框中插入评论,单击“ SendMail”,然后我在电子邮件框中收到他的评论。 This code doesn't seem to work properly, when a Windows10 user hits SendMail. 当Windows10用户点击SendMail时,此代码似乎无法正常工作。 I get an e-mail with a subject but the body is empty. 我收到一封包含主题的电子邮件,但正文为空。

See below the code that works for any other Windows (Please note EmailBox is the name for the TextBox where the user inputs his questions): 请参阅下面的代码,该代码适用于任何其他Windows(请注意,EmailBox是用户在其中输入问题的TextBox的名称):

Private Sub SendEmail1_Click()

Dim OutApp As Object
Dim OutMail As Object
Dim strText As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .Body = EmailBox
        .To = "random.email@yahey.com"
        .CC = ""
        .BCC = ""
        .Subject = "Question about random stuff"
        .Send
    End With

    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    Unload Me
End Sub

Anyone has any ideas?? 任何人有任何想法吗?

As per Nathan_Sav comment, added .value to the body line and it worked perfectly. 根据Nathan_Sav注释,将.value添加到正文行中,并且效果很好。

.Body = EmailBox.value

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM