簡體   English   中英

Excel VBA電子郵件行發送給單個收件人

[英]Excel VBA Email Rows to a Single Recipient

我有一個跟蹤發票的工作表,我試圖生成一個自動電子郵件程序,如果第12列中的單元格包含AUTOEMAIL,它將把所有行與使用TRIM函數生成的相似電子郵件地址合並。 它將所有類似的行(基於列15的電子郵件地址)拉入LotusNotes電子郵件中。 羅恩·德布魯因(Ron De Bruin)在他的網站上有一些很棒的例子。 我試圖編寫一個循環,該循環試圖循環並根據電子郵件地址復制所有行。 當我去運行時,代碼不執行任何操作,但是沒有出現錯誤。 在Outlook中有在線實例可以完成此操作,但是它們不適用於LotusNotes,因為該問題是后期綁定還是早期綁定。 我也是VBA自動化的新手。

    Sub Send_Data()
Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim vaRecipient As Variant
Dim rnBody As Range
Dim Data As DataObject

Const stSubject As String = "TEST"
Const stMsg As String = "TEST"
Const stPrompt As String = "Please select the range:"

lastrow = Range("N" & Rows.Count).End(xlUp).row
For Each Cell In Range("N8:N" & lastrow)
If WorksheetFunction.CountIf(Range("N8:N" & Cell.row), Cell) = 1 Then
If Cells(Cell.row, 11) = "AUTOEMAIL" Then

rnBody = "Hello" & vbNewLine & vbNewLine & _
ActiveCell.EntireRow.Select


On Error Resume Next

'The user canceled the operation.
If rnBody Is Nothing Then Exit Sub

On Error GoTo 0

'Instantiate Lotus Notes COM's objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")

'Make sure Lotus Notes is open and available.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL

'Create the document for the e-mail.
Set noDocument = noDatabase.CreateDocument

 'Copy the selected range into memory.
 rnBody.Copy

 'Retrieve the data from then copied range.
 Set Data = New DataObject
 Data.GetFromClipboard

 'Add data to the mainproperties of the e-mail's document.
 With noDocument
   .Form = "Memo"
   .SendTo = vaRecipient
   .Subject = stSubject
   'Retrieve the data from the clipboard.
   .Body = stMsg & " " & Data.GetText
    .SaveMessageOnSend = True
 End With

 ' SEND EMAIL
 With noDocument
   .PostedDate = Now()
   .Send 0, vaRecipient
End With

' REMOVE FROM MEMORY
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing


'SWITCH BACK TO EXCEL
AppActivate "Microsoft Excel"

'EMPTY COPY-PAST CLIPBOARD
Application.CutCopyMode = False
' DISPLAYS TO USER IF SUCCESSFUL
MsgBox "Complete!", vbInformation
  End If
 End If
Next Cell
End Sub

我將電子郵件正文范圍設置為“提示框”,用戶可以在其中突出顯示單元格,然后在另一個提示框中,它要求輸入使用TRIM()函數創建的電子郵件。 我意識到,代碼的設置方式無法滿足我的要求。 新方法效果很好

Treevar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM