我有一个主要表单,其中有一个' help'按钮打开一个带有文本框的简单表单,用户可以使用该文本框提交主表单中提到的问题。我希望用户在文本框中键入的内容通过电子邮件发送给我自己以及使用'发送'按钮。
我在stackoverflow上找到了以下代码,除了我无法弄清楚如何让电子邮件正文包含用户在文本框中输入的内容而不是当前在文本框中输入的静态文本。代码。
以下是代码的外观:
Private Sub SendEmail_Click()
Dim olApp As Object
Dim objMail As Object
Dim Issue As String
strIssue = Me.ContactMessageBox
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.To = "emailaddress.com"
.Subject = "Form issue"
.Body = "strIssue"
.send
End With
MsgBox "Operation completed successfully"
End Sub
有没有人有关于如何做到这一点的想法?
提前致谢。
答案 0 :(得分:1)
更改
Dim Issue As String
strIssue = Me.ContactMessageBox
...
.Body = "strIssue"
到
Dim strIssue As String
strIssue = Me.ContactMessageBox
...
.Body = strIssue
如果您将变量放在“”之间,那么它将被读取为字符串而不是变量。