在excel中使用命名范围作为电子邮件列表

时间:2018-04-27 13:13:11

标签: excel vba

我是新来的,只是学习编码。我正在处理Excel表单,我需要在单独的工作表上使用命名范围作为电子邮件列表。有没有办法将其添加到.To =字段?

Private Sub Email_Click()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = Range("G2") & " Shift Turnover Report is attached"
              On Error Resume Next
With xOutMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = Range("G2") & " Shift Turnover Report"
    .Body = xMailBody
    .Attachments.Add Application.ActiveWorkbook.FullName
    .Send
End With
If Err Then
  MsgBox "Hmmm. Something went wrong." & vbLf & "Please try again.", vbExclamation
Else
  MsgBox "Your message has been sent.", vbInformation
End If
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情......

#ifndef MyFile_hpp
#define MyFile_hpp

#ifdef __cplusplus
extern "C" {
#endif

void runCode();

#ifdef __cplusplus
}
#endif

#endif