我有一个 Word 文档,其中包含一个带有电子邮件地址的表格。我想从文档中获取地址并打开一个 Lotus Notes 电子邮件,该电子邮件设置为默认电子邮件服务,将地址添加到“收件人:”字段并将文档作为附件。我已经连接到 Lotus Notes,我只想让邮件开始有地址和附件,而不是自动发送。我有从表中获取地址的代码:
Sub Send_mail_recipients()
'NiMo 08-Jun-2013
'Send-mail to distribution list
Dim Text As String
Dim char As String
Dim rowcount, n_address, n_cells, Cell_Crt, CharNo As Integer
Dim Recipient(100) As Variant
'With Application.ActiveWindow.Document
'Activate the Document
'n_address = 0
Text = ""
ActiveDocument.Tables(2).Select
n_cells = Selection.Cells.Count
For Cell_Crt = 1 To n_cells
If Selection.Cells(Cell_Crt).Range.Text Like "*@*" Then
'Recipient(n_address) = Selection.Cells(Cell_Crt).Range.Text
Text = Text + Selection.Cells(Cell_Crt).Range.Text + ", "
'n_address = n_address + 1
End If
'Text = Selection.Cells(Cell_Crt).Range.Text
Next
Visual basic 提供了一种方法来打开包含文档作为附件的邮件:
'If n_address = 0 Then
If Text = "" Then
myerrmessage = MsgBox("The Document has no email addresses!", vbOKOnly, "error")
Else
Options.SendMailAttach = True
ActiveDocument.SendMail
我发现了另一个函数,它将我作为参数提供的电子邮件地址添加到邮件中:
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Function OpenEmail(ByVal EmailAddress As String, _
Optional Subject As String, Optional Body As String) _
As Boolean
Dim lWindow As Long
Dim lRet As Long
Dim sParams As String
sParams = EmailAddress
If LCase(Left(sParams, 7)) <> "mailto:" Then _
sParams = "mailto:" & sParams
If Subject <> "" Then sParams = sParams & "?subject=" & Subject
If Body <> "" Then
sParams = sParams & IIf(Subject = "", "?", "&")
sParams = sParams & "body=" & Body
End If
lRet = ShellExecute(lWindow, "open", sParams, _
vbNullString, vbNullString, SW_SHOW)
OpenEmail = lRet = 0
End Function
OpenEmail Text, "", ""
但是我需要一种方法来在同一封邮件中同时包含地址和附件。