2016-11-07 205 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?你有没有尝试过两个用户名? –

相关问题