2017-01-09 85 views
1

我試圖觸發宏當用戶在列N.Excel的VBA:使用IBM注

電子郵件必須使用IBM筆記發送更新我的手機,這將一封電子郵件發送HTML電子郵件。 下面的代碼,發送電子郵件罰款。但是,我不熟悉IBM筆記,我想嘗試將我的電子郵件格式化爲HTML。

目前,電子郵件正在發送純文本。

Private Sub Worksheet_Change(ByVal Target As Range) 

If Not Intersect(Target, Range("M:M")) Is Nothing Then 
    If Target.Cells.Count < 3 Then 



    'Set up the objects required for Automation into lotus notes 
    Dim Maildb As Object 'The mail database 
    Dim UserName As String 'The current users notes name 
    Dim MailDbName As String 'THe current users notes mail database name 
    Dim MailDoc As Object 'The mail document itself 
    Dim AttachME As Object 'The attachment richtextfile object 
    Dim session As Object 'The notes session 
    Dim EmbedObj As Object 'The embedded object (Attachment) 
    Dim Ref As String 
    Dim TrueRef As String 


    Ref = Range("H" & (ActiveCell.Row)).Value 

    If Ref = "WSM" Then 
    TrueRef = "WES" 
    Else 
    If Ref = "NAY" Then 
    TrueRef = "NAY" 
    Else 
    If Ref = "ENF" Then 
    TrueRef = "ENF" 
    Else 
    If Ref = "LUT" Then 
    TrueRef = "MAG" 
    Else 
    If Ref = "NFL" Then 
    TrueRef = "NOR" 
    Else 
    If Ref = "RUN" Then 
    TrueRef = "RUN" 
    Else 
    If Ref = "SOU" Then 
    TrueRef = "SOU" 
    Else 
    If Ref = "SOU" Then 
    TrueRef = "SOU" 
    Else 
    If Ref = "BRI" Then 
    TrueRef = "BRI" 
    Else 
    If Ref = "LIV" Then 
    TrueRef = "LIV" 
    Else 
    If Ref = "BEL" Then 
    TrueRef = "BEL" 
    End If 
    End If 
    End If 
    End If 
    End If 
    End If 
    End If 
    End If 
    End If 
    End If 
    End If 




    'Start a session to notes 
    Set session = CreateObject("Notes.NotesSession") 

    'Next line only works with 5.x and above. Replace password with your password 
    'Session.Initialize ("password") 
    'Get the sessions username and then calculate the mail file name 
    'You may or may not need this as for MailDBname with some systems you 
    'can pass an empty string or using above password you can use other mailboxes. 
    UserName = session.UserName 
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf" 

    'Open the mail database in notes 
    Set Maildb = session.GETDATABASE("", MailDbName) 
    If Maildb.IsOpen = True Then 
     'Already open for mail 
    Else 
     Maildb.OPENMAIL 
    End If 

    'Set up the new mail document 
    Set MailDoc = Maildb.CREATEDOCUMENT 
    MailDoc.Principal = "[email protected]" 
    MailDoc.ReplyTo = "[email protected]" 
    'MailDoc.DisplaySent = "[email protected]" 
    'MailDoc.iNetFrom = "[email protected]" 
    'MailDoc.iNetPrincipal = "[email protected]" 
    MailDoc.Form = "Memo" 
    MailDoc.sendto = "Supplychain-" & TrueRef & "@inbox.co.uk" 
    MailDoc.subject = "L.O. Delivery Tracker: The status of your Issue has been updated." 





    MailDoc.HTMLbody = "<html><body><p>Hello</p><p>Please find attached the above invoices and backup.</p>" _ 
    & "<p>Any queries please let me know</p><p>Regards</p>" & Signature & "</body></html>" 
    MailDoc.SAVEMESSAGEONSEND = SaveIt 



    'Send the document 
    MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder 
    MailDoc.SEND 0, Recipient 

    'Clean Up 
    Set Maildb = Nothing 
    Set MailDoc = Nothing 
    Set AttachME = Nothing 
    Set session = Nothing 
    Set EmbedObj = Nothing 






    End If 
End If 

End Sub 

請有人能告訴我我需要做什麼才能讓這封電子郵件發送爲html嗎?謝謝

回答

0

首先,您可能希望使用Lotus.NotesSession對象而不是Notes.NotesSession對象。 Notes.NotesSession類使用OLE,它要求Notes客戶機在您調用時必須正在運行。 Lotus.NotesSession類使用COM,它不要求Notes客戶端正在運行 - 儘管它必須被安裝。

至於通過Notes API發送HTML郵件,您可以參考this IBM Technote。該筆記中使用的語言是LotusScript,但概念和類是相同的,語法與VBA非常相似。我不確定的一件事是它使用的NotesStream類是否通過COM API公開。 (另請參見answer to a previous StackOverflow question。其中的註釋表明NotesStream類不可用,但在這種情況下,提問者也使用OLE類,而不是COM類。)