2016-11-07 204 views
0

我看到了一些用於加載Lotus Notes並將附件放入併發送出去的宏。 它幾乎完成它發送電子郵件,但不知道如何發送文件夾,它與PDF文件一起使用,但我想在一個文件夾中發送一堆PDF文件。 我如何格式化的電子郵件爲: 「 你好如何打開Lotus Notes新郵件併發送

請查看附件

(附件)

簽名 」

任何幫助表示讚賞,感謝

Sub SendEmail() 
Dim WatchRange As Range 
Dim IntersectRange As Range 
Dim x As Integer 
Dim UserName As String 
Dim MailDbName As String 
Dim Recipient As Variant 
Dim Maildb As Object 
Dim MailDoc As Object 
Dim Attachment As String 
Dim Session As Object 
Dim stSignature As String 
With Application 
.ScreenUpdating = False 
.DisplayAlerts = False 
' Open and locate current LOTUS NOTES User 
Set Session = CreateObject("Notes.NotesSession") 
UserName = Session.UserName 
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1,   UserName, " "))) & ".nsf" 
Set Maildb = Session.GETDATABASE("", MailDbName) 
If Maildb.IsOpen = True Then 
Else 
Maildb.OPENMAIL 
End If 
' Create New Mail and Address Title Handlers 
Set MailDoc = Maildb.CREATEDOCUMENT 
MailDoc.Form = "Memo" 
Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0) 
' Select range of e-mail addresses 
MailDoc.SendTo = "joe bloggs" 
MailDoc.subject = "Work" 
MailDoc.Body = "Hello" & " " & " Please find attachment." 
MailDoc.SAVEMESSAGEONSEND = True 
Attachment = "c:\03-11\4267.pdf" 
If Attachment <> "" Then 

    Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment") 
    Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "") 
    On Error Resume Next 
    MailDoc.CREATERICHTEXTITEM ("Attachment") 
End If 

    MailDoc.PostedDate = Now() 
    On Error GoTo errorhandler1 
MailDoc.SEND 0, Recipient 
Set Maildb = Nothing 
Set MailDoc = Nothing 
Set Session = Nothing 
.ScreenUpdating = True 
.DisplayAlerts = True 
    On Error GoTo errorhandler1 
    Set Maildb = Nothing 
    Set MailDoc = Nothing 
    Set Session = Nothing 
End With 
End Sub 

我改變了我的宏,它nows添加簽名但格式不正確,並且不附加文件。

Sub SendEmail() 

    Dim WatchRange As Range 
    Dim IntersectRange As Range 
    Dim x As Integer 
    Dim UserName As String 
    Dim MailDbName As String 
    Dim Recipient As Variant 
Dim Maildb As Object 
Dim MailDoc As Object 
Dim Attachment As String 
Dim Session As Object 
    Dim stSignature As String 
Dim ws As Object 'Lotus Workspace 


    Dim objProfile As Object 
    Dim rtiSig As Object, rtitem As Object, rtiNew As Object 
    Dim uiMemo As Object 
    Dim strToArray() As String, strCCArray() As String, strBccArray() As String 
Dim strTo As String, strCC As String, strBcc As String, _ 
strObject As String, strBody As String, strAttachment As String, blnSaveit As Boolean 
    Dim strSignText As String, strMemoUNID As String 
    Dim intSignOption As Integer 


    With Application 
    .ScreenUpdating = False 
    .DisplayAlerts = False 
    ' Open and locate current LOTUS NOTES User 
    Set Session = CreateObject("Notes.NotesSession") 
    Set ws = CreateObject("Notes.NotesUIWorkspace") 

    UserName = Session.UserName 
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf" 
    Set Maildb = Session.GETDATABASE("", MailDbName) 
    If Maildb.IsOpen = True Then 
    Else 
    Maildb.OPENMAIL 
    End If 
    ' Create New Mail and Address Title Handlers 


    Set MailDoc = Maildb.CREATEDOCUMENT 
    MailDoc.Form = "Memo" 
    stSignature =      Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0) 
    ' Select range of e-mail addresses 
    MailDoc.SendTo = "JJunoir" 
    MailDoc.subject = "" 
    MailDoc.Body = "Hello" & " " & " Please find attachment," 
     MailDoc.SAVEMESSAGEONSEND = True 


     Set objProfile = Maildb.GETPROFILEDOCUMENT("CalendarProfile") 
     intSignOption = objProfile.GETITEMVALUE("SignatureOption")(0) 
     strSignText = objProfile.GETITEMVALUE("Signature")(0) 


     Attachment = "c:\Debit Notes 03-11\" 
    If strAttachment <> "" Then 
    Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment") 
    Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", strAttachment,  "Attachment") 
    On Error Resume Next 
    MailDoc.CREATERICHTEXTITEM ("Attachment") 
    End If 


    'Open memo in ui 
    Set uiMemo = ws.EDITDOCUMENT(True, MailDoc) 
    Call uiMemo.GotoField("Body") 

    'Check if the signature is automatically inserted 
    If objProfile.GETITEMVALUE("EnableSignature")(0) <> 1 Then 
    If intSignOption = 2 Then 
    Call uiMemo.ImportItem(objProfile, "Signature_Rich") 
    End If 
    End If 

    Call uiMemo.GotoField("Body") 
    'Save the mail doc 
    strMemoUNID = uiMemo.DOCUMENT.UNIVERSALID 
    uiMemo.DOCUMENT.MailOptions = "0" 
    Call uiMemo.Save 
    uiMemo.DOCUMENT.SaveOptions = "0" 
    Call uiMemo.Close 
    Set uiMemo = Nothing 
    Set MailDoc = Nothing 

    'Get the text and the signature 
    Set MailDoc = Maildb.GETDOCUMENTBYUNID(strMemoUNID) 
    Set rtiSig = MailDoc.GETFIRSTITEM("Body") 
    Set rtiNew = MailDoc.CREATERICHTEXTITEM("rtiTemp") 
    Call rtiNew.APPENDTEXT(strBody) 
    Call rtiNew.APPENDTEXT(Chr(10)): Call rtiNew.APPENDTEXT(Chr(10)) 
    Call rtiNew.APPENDRTITEM(rtiSig) 
    'Remove actual body to replace it with the new one 
    Call MailDoc.RemoveItem("Body") 
    Set rtitem = MailDoc.CREATERICHTEXTITEM("Body") 
    Call rtitem.APPENDRTITEM(rtiNew) 

    MailDoc.Save False, False 
    Set uiMemo = ws.EDITDOCUMENT(True, MailDoc) 


    MailDoc.PostedDate = Now() 
    On Error GoTo errorhandler1 
    MailDoc.SEND 0, Recipient 
    Set Maildb = Nothing 
    Set MailDoc = Nothing 
    Set Session = Nothing 
    .ScreenUpdating = True 
    .DisplayAlerts = True 
    errorhandler1: 
    Set Maildb = Nothing 
    Set MailDoc = Nothing 
    Set Session = Nothing 
    End With 
    End Sub 

這是它沒有附着物 親切的問候 ĴJuniorHello請查收附件,生產

+0

我已經更新了以前的宏到這個新的宏。有人可以解釋這一行Set AttachME = MailDoc.CREATERICHTEXTITEM(「Attachment」) Set EmbedObj = AttachME.EMBEDOBJECT(1454,「」,Attachment,「」) –

+0

這現在增加了一個換行符MailDoc.Body =「Hello」&vbNewLine &vbNewLine&「請查找附件」,&vbNewLine。我仍然試圖尋找解決方案來添加簽名。 –

回答

1

如果你的目標是操作Lotus Notes客戶端的用戶界面,然後你開始半正確使用「 Notes.NotesSession「而不是」Lotus.NotesSession「。筆記。」前綴會讓你獲得OLE classes而不是你用「Lotus」前綴得到的COM類,而且你肯定需要使用OLE類 - 但是你仍然選擇了錯誤的根對象。

NotesSession類及其下降的所有類都可以在OLE和COM類中使用,它們被稱爲「後端類」,這意味着它們根本不操作用戶界面。

如果您想操作UI,並且其根目標爲「Notes.NotesUIWorkspace」,則需要使用「前端類」。在很多情況下,您可能會發現需要後端和前端類的組合。例如,NotesUIWorkspace.EditDocument(前端)採用NotesDocument(後端)參數,允許您通過在幕後找到它來打開您找到的文檔的UI。

+0

現在,它不適用於Line Username = Session.Username。運行時錯誤438.對象不能正確支持此操作。我可以改變它到什麼? –

+0

如果您需要/想要使用UI類(操作用戶界面)和後端類(從NotesSession對象獲取用戶名),則需要實例化兩者。 –

+0

您現在在使用哪個會話課程? Notes.NotesSesison或Lotus.NotesSession?你有沒有嘗試過兩個用戶名? –

相關問題