VBA-Insert body of email above signature using Lotus Notes

此生再无相见时 提交于 2020-01-15 09:19:13

问题


What I am trying to achieve is very simple, insert the body of an email above the signature in lotus notes. The code I have in vba, when run, opens a new email window in lotus notes pastes in the Subject, SendTo and Body fields. Everything works perfectly, but when the body is inserted it puts the text below my signature. I've done a ton of digging to try and find a solution, but haven't found anything that has worked just right. A few posts I've found suggest removing the signature, pasting the body and then rebuilding the signature into the email--not really the approach i'd like.

Here is my code:

Sub CreateEmail()

        Dim Notes As Object
        Dim Maildb As Object
        Dim objNotesDocument As Object
        Dim objNotesField As Object

        Set Notes = CreateObject("Notes.NotesSession")
        Set Maildb = Notes.GETDATABASE("", "")
        Maildb.OPENMAIL
        Set objNotesDocument = Maildb.CREATEDOCUMENT

        Subject = "Hey look at my email!!"
        Set objNotesField = objNotesDocument.APPENDITEMVALUE("Subject", Subject)
        Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", GetPrimaryEmail) 'calls a function to return the SendTo 
        Set objNotesField = objNotesDocument.APPENDITEMVALUE("Body", bodyInfo)  'calls a function to return the body contents. 

        Set workspace = CreateObject("Notes.NotesUIWorkspace")
        Call workspace.EDITDOCUMENT(True, objNotesDocument)

        AppActivate "Lotus Notes"

   End Sub

Thanks in advance for any help!


回答1:


A different approach to set the Body content is to open the new document in edit mode (like you do at the end of your code) and then set cursor to Body field and insert the text. Your code could look like this:

    ...
    Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", GetPrimaryEmail) 'calls a function to return the SendTo 

    Set workspace = CreateObject("Notes.NotesUIWorkspace")
    Call workspace.EDITDOCUMENT(True, objNotesDocument)
    Set uidocument = workspace.CurrentDocument
    Call uidocument.GotoField("Body")
    Call uidocument.InsertText(bodyInfo)  'calls a function to return the body contents. 

    AppActivate "Lotus Notes"


来源:https://stackoverflow.com/questions/25455524/vba-insert-body-of-email-above-signature-using-lotus-notes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!