Link to home
Start Free TrialLog in
Avatar of Hammer8
Hammer8Flag for United States of America

asked on

VBA and Lotus Notes: Using VBA to create Notes email with 2 (or more) attachments and have Notes open email for user edit before sending

Hi, I am trying to write VBA code which will do the above.  I have search this site and many others looking for a solution, but have not been able to find one.  I am able to build the email and save it in the drafts folder, but cannot find a way to reference that document in UIWorkspace so I can edit it with EDITDOCUMENT.  I am getting the following error #4719 Incorrect argument type: object expected.

I have searched for days for a solution and found many others who have the same problem: which is trying to edit a "backend" document in UIWorkspace.  Is there a workaround to this?

An alternative to passing doc to  uiws.EDITDOCUMENT(True, doc) would be to some how select the document created which now sits in the Drafts folder and use uiws.EditDocument(True), but I also cannot figure out how to find and select the document created and saved by the VBA code.  

Thanks!  Hammer  
Sub SendTradeEmailNotes(subject, too, cc, bcc, htmlpath, Tickers() As String)
    Dim session As Object
    Dim MailDb As Object
    Dim MailDoc As Object
    Dim oAttachME As Object
    Dim oEmbedObj As Object
 
    Dim uiWS As Object
    Dim uiDoc As Object
 
    Dim parent As NotesMIMEEntity
    Dim Child() As NotesMIMEEntity
    Dim header As NotesMIMEHeader
    Dim stream As NotesStream
    Dim doc As NotesDocument
    Dim collection As NotesDocumentCollection
    
    Dim View As NotesView
    Dim uiView As NOTESUIVIEW
    
    Dim i, j, X, Childs, response, lngError, rtitem, UNID
    
    Set session = CreateObject("Lotus.NotesSession")
    Call session.Initialize
 
    Set MailDb = session.GetDbDirectory("Accout").OpenMailDatabase
 
    If MailDb.IsOpen = True Then
        'Already open for mail
    Else
        Call MailDb.Open
    End If
 
    Set doc = MailDb.CreateDocument
    Call doc.ReplaceItemValue("Form", "Memo")
    Call doc.ReplaceItemValue("Subject", subject)
 
    ' Create all the Entities - one parent, X children depending on number of attachments
    Set parent = doc.CreateMIMEEntity
    
    Childs = UBound(Tickers()) + 1
    
    ReDim Child(1 To Childs)
    Set Child(1) = parent.CreateChildEntity
    
    ' Add a couple of headers to child 2 (that will hold the attachment).
 
    j = UBound(Tickers())
 
    For i = 1 To j
        ' Bring the attachment into its entity (child 2)
        Set stream = session.CreateStream
        If FileOrDirExists("C:\" & Tickers(j - i + 1) & " Trades.txt") Then
            Set Child(i + 1) = parent.CreateChildEntity(Child(i))
            
            Set header = Child(i + 1).CreateHeader("Content-Transfer-Encoding")
            Call header.SetHeaderVal("binary")
            Set header = Child(i + 1).CreateHeader("Content-Disposition")
            Call header.SetHeaderVal("attachment; filename=" & Tickers(j - i + 1) & " Trades.txt")
 
            X = stream.Open("C:\" & Tickers(j - i + 1) & " .txt", "binary")
            Call Child(i + 1).SetContentFromBytes(stream, "text/plain", ENC_NONE)
            Call Child(i + 1).EncodeContent(ENC_IDENTITY_8BIT)
            Call stream.Close
        End If
    Next i
    Call doc.AppendItemValue("Form", "Memo")
    doc.Save True, True
    UNID = doc.UniversalID
 
    Set uiWS = CreateObject("Notes.NotesUIWorkspace")
    Set uidoc = uiws.EDITDOCUMENT(True, doc)  '<---------------Error Here!!!
 
    X = Shell("C:\Program Files\Lotus\Notes\notes.exe", vbNormalFocus)
 
    Call uiDoc.GOTOFIELD("To")
    Call uiDoc.InsertText(too)
    
    Call uiDoc.GOTOFIELD("EnterCopyTo")
    Call uiDoc.InsertText(cc)
    
    Call uiDoc.GOTOFIELD("Subject")
    Call uiDoc.InsertText(subject)
    
    Call uiDoc.GOTOFIELD("Body")
    Call uiDoc.GOTOBOTTOM
    
    Call uiDoc.Import("HTML File", htmlpath)
    
    Call uiDoc.GOTOFIELD("Body")
    Call uiDoc.GOTOTOP
 
    Set doc = Nothing
 
    Set session = Nothing
    Set MailDb = Nothing
    Set MailDoc = Nothing
    Set oAttachME = Nothing
    Set oEmbedObj = Nothing
    Set uiWS = Nothing
    Set uiDoc = Nothing
 
End Sub

Open in new window

Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Strange... Here's a similar question:
https://www.experts-exchange.com/questions/23972184/I-need-to-show-a-prepared-email-in-Lotus-Notes-that-the-user-can-change.html

Here's part of the explanation:
http://www-10.lotus.com/ldd/nd6forum.nsf/d6091795dfaa5b1185256a7a0048a2d0/9618bfa540b65896852571e300596d14?OpenDocument

I think if you switch to .Net you might pull this off, but I'm not sure (not being dot-netter, that is)...
Avatar of Hammer8

ASKER

Thanks, unfortunately I must do this in Excel VBA...Hammer
Another suggestion:
http://www.bigresource.com/VB-VB-and-Lotus-Notes-BAmUHAi2y.html

Instead of Lotus.NotesSession, try Notes.NotesSession.
Avatar of Hammer8

ASKER

Hi - just tried that and using Set session = CreateObject("Notes.NotesSession") gives me an Error 438.
Run-time error "438": Object doesn't support this property or method.

Thanks, Henry
Pity...

And one change for the NotesUIWorkspace:

    Set uiWS = CreateObject("Lotus.NotesUIWorkspace")
    Set uidoc = uiws.EDITDOCUMENT(True, doc)  '<---------------Error Here!!!

I don't think this will work either. Conclusion: the Notes Help is correct, the object is not supported in COM.
 
This one's a bit tricky, but here's how I do it.

NOTE: This solution will destroy whatever is on the Windows clipboard, so you may want to add some code to save and restore the clipboard contents.
Sub Test()
 
  Dim html As String
  Dim attachments(0) As String
  html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'>This is a test!</div>"
  attachments(0) = "c:\temp\any_file.txt"
  Call ComposeMemo("some.user@acme.com", "Test from Excel", html, attachments)
 
End Sub
 
Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String)
 
  Dim sess As Object, db As Object, doc As Object
  Dim stream As Object, body As Object, ws As Object
  Dim convertMime As Boolean
  Const ENC_QUOTED_PRINTABLE = 1726
  Const EMBED_ATTACHMENT = 1454
  
  ' Create a temp email doc
  Set sess = CreateObject("Notes.NotesSession")
  Set ws = CreateObject("Notes.NotesUiWorkspace")
  Set db = sess.GetDatabase("", "")
  Call db.OpenMail
  Set doc = db.CreateDocument()
  Call doc.ReplaceItemValue("Form", "Memo")
  
  ' add the body as a mime html part and copy it to the clipboard
  convertMime = sess.convertMime
  sess.convertMime = False
  Set stream = sess.CreateStream()
  stream.WriteText (html)
  Set body = doc.CreateMIMEEntity("Body")
  Call body.SetContentFromText(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
  Call stream.Close
  sess.convertMime = convertMime
  Call doc.CloseMIMEEntities(True, "Body")
  Call doc.Save(True, False)
  Set uidoc = ws.EditDocument(True, doc)
  Call uidoc.GotoField("Body")
  Call uidoc.SelectAll
  Call uidoc.Copy
  uidoc.Document.SaveOptions = "0"
  uidoc.Document.MailOptions = "0"
  Call uidoc.Close
  Call doc.Remove(True)
  
  ' add file attachment(s) to htlp and copy to the clipboard
  Set doc = db.CreateDocument()
  Call doc.ReplaceItemValue("Form", "Memo")
  Set body = doc.CreateRichTextItem("Body")
  Dim i As Integer
  For i = 0 To UBound(attachments)
    Call body.EmbedObject(EMBED_ATTACHMENT, "", attachments(i))
  Next
  Call doc.Save(True, False)
  Set uidoc = ws.EditDocument(True, doc)
  Call uidoc.GotoField("Body")
  Call uidoc.Paste
  Call uidoc.InsertText(Chr$(10) & Chr$(10))
  Call uidoc.SelectAll
  Call uidoc.Copy
  uidoc.Document.SaveOptions = "0"
  uidoc.Document.MailOptions = "0"
  Call uidoc.Close
  Call doc.Remove(True)
 
  ' compose the memo and paste the rendered html and file(s)
  Set uidoc = ws.ComposeDocument(db.Server, db.filePath, "Memo")
  Call uidoc.FieldSetText("EnterSendTo", sendto)
  Call uidoc.FieldSetText("Subject", subject)
  Call uidoc.GotoField("Body")
  Call uidoc.Paste
 
  ' bring the window to the front
  Call AppActivate(uidoc.WindowTitle)
 
End Sub

Open in new window

But what's the difference?? If all earlier CreateObjects failed, why should this one work for him? It seems more likely that there is some installation error in Notes, for I see examples all over the place of using similar code. Puzzled...

And Happy New Year!
>> "But what's the difference?? If all earlier CreateObjects failed, why should this one work for him?"

There are many things wrong in the original source above such as the mixed use of COM and OLE to access the same objects.  That is most likely the cause of the error, but I'd like to see him run my code to make sure it works on his machine.
Avatar of Hammer8

ASKER

Wow!  I can't believe it is working - thank you so much!  The only hitch is that the icon for the text file is a grey generic icon instead of the normal notepad icon.  Is there a workaround to that?  Thank you so much!  I am just amazed at this point!  Hammer
Can't find the OLE in the code.  :-S  You must be right though...
Avatar of Hammer8

ASKER

Bill - actuall, another issue came up - the html code I am sending has a couple of GIF's in it.  The path to the GIF's is on our LAN (say s:\ABC.GIF).  When I run the code now, it gives me an error Cannot save bitmap to disk...but this is so close!  Thank you again.  Hammer.
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> "When I run the code now, it gives me an error Cannot save bitmap to disk"

At what point does the error occur?

>> "The path to the GIF's is on our LAN"

If you suspect that the LAN is causing the error, try copying the gifs to a temp folder, then operate of the temp files.
Thanks for explaining, Bill!

@Hammer8: in case you were considering to give me points (very unlikely), don't.
Avatar of Hammer8

ASKER

Hi, I was able to get around the embedded GIF issue by using  uiDoc.Import("HTML File", htmlpath), and the email looks great (besides the grey icons) in Notes, but if I send it to an email account using Outlook, the pictures don't appear.  Any ideas?  I am running Outlook and Notes on the same machine and so both should have access to the S:\ABC.GIF file, although I would have hoped Notes would embedded the actual picture in the email instead of a link to it?  Thanks again and still amazed - Hammer.
Don't feel too bad.  You have no idea how long it took me to figure this all out (lots of trial and error).  There's not much documentation on the differences between the two, and most of the sample code I found out there is wrong.
Sorry, we cross-posted.  My last comment was directed towards sjef.

>> "if I send it to an email account using Outlook, the pictures don't appear"

I'm not sure about this one.  It could be a server setting on your side or on the exchange side (just a guess).

Sjef, here's your chance!  Jump in!
Avatar of Hammer8

ASKER

I am new to experts-exchange - how do I give points?  But accepting the solution?  I want to make sure I do it right since your help is very much appreciated.  Hammer.
Yes, just click the Accept Solution button and follow the prompts.
>> "I would have hoped Notes would embedded the actual picture in the email instead of a link to it?"

Does the picture display as a link in Notes and Outlook or just Outlook?
Outlook?? Oh no, yuck, not me... Unknown territory, and I intend to keep it that way... :-))
Avatar of Hammer8

ASKER

I don't know how to tell the difference...I will open another question for this particular issue.  Thanks!
Avatar of Hammer8

ASKER

Bill, here is some code that I found to attach files which does generate the proper icons in Notes.  However, it does not work with the code you gave me.  Am I mixing OLE and COM again?  Since you code uses Dim doc As object, I cannot use doc.CreateMIMEEntity.  In the code that works with below, I use Dim doc As NotesDocument.  Thanks, Hammer8


    Set parent = doc.CreateMIMEEntity
    ReDim Child(1 To j + 1)
    Set Child(1) = parent.CreateChildEntity  ' Create so that children 1 & 2 are siblings
 
    For i = 1 To j
        ' Bring the attachment into its entity (child 2)
        Set stream = session.CreateStream
        If FileOrDirExists("C:\" & Tickers(j - i + 1) & " Trades.txt") Then
            Set Child(i + 1) = parent.CreateChildEntity(Child(i))
            
            Set header = Child(i + 1).CreateHeader("Content-Transfer-Encoding")
            Call header.SetHeaderVal("binary")
            Set header = Child(i + 1).CreateHeader("Content-Disposition")
            Call header.SetHeaderVal("attachment; filename=" & Tickers(j - i + 1) & " Trades.txt")
 
            X = stream.Open("C:\" & Tickers(j - i + 1) & " Trades.txt", "binary")
            Call Child(i + 1).SetContentFromBytes(stream, "text/plain", ENC_NONE)
            Call Child(i + 1).EncodeContent(ENC_IDENTITY_8BIT)
            Call stream.Close
        End If
    Next i

Open in new window

>> "Am I mixing OLE and COM again?"

I think so.  If I'm correct, you added a reference to the "Lotus Domino Objects" to your project.  That is the COM object library.  If you do have this reference loaded, you need to select "Tools \ References..." and uncheck that library.

Now, in a perfect world, I would tell you to add a reference to the "Lotus Notes Automation Classes" library since that is the one that contains the OLE classes (which is what we need).  But alas, OLE class libraries do not function well when loaded as a project reference in VBA, so don't load any Lotus libraries.

>> "Since you code uses Dim doc As object, I cannot use doc.CreateMIMEEntity"

Not true.

What I use in my VBA code is called "late-binding".  This simply means that the compiler does not know the class type until run-time.  When you declare a variable using a class library reference, it is called "early-binding" because the compiler knows the class type at design-time.  Regardless of the method used, the objects at run-time are identical and have the same methods available.  My guess is that you are trying to call CreateMIMEEntity in a mixed environment of OLE and COM objects which is not supported.

The solution is to unload all Lotus class libraries and use late-binding exclusively.  Yes, you loose the type-ahead feature, but the code actually works.  :)

So, in addition to the guidelines posted above, I'll add...

4.  Don't use the "Lotus Notes Automation Classes" in VBA (use late-binding only if you need to access the UI).

5. Declare all Lotus objects as 'Object'.

6. Instantiate NotesSession and NotesUIWorkspace using CreateObject("Notes.NotesSession") and CreateObject("Notes.NotesUiWorkspace").

This might sound scary, but there are only two objects that need to be instantiated using CreateObject.  They are NotesSession and NotesUIWorkspace.  All other objects are created by calling the methods of one of these two classes (ie: CreateDocument, EditDocument, etc).  Since all other objects are being created and returned by the library, the type is guaranteed to be correct, and they will play nicely together.

I hope this helps.  I know It's confusing.  Keep at it, and soon all will become clear.   :)
I'm really glad you asked this question!

It made me re-examine the old, clunky copy-paste method I've been using and now I have a function that will compose mime memos with file attachments and inline images.  The best part is that the new function uses pure mime (no more mime-this and richtext-that).   There is still a copy-paste at the end of the function, but that is only required if you need the user's signature to appear.

Tell me what you think!
Sub Test()
 
  Dim html As String
  Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
  html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:any_jpeg.jpg'>This is a test!</div>"
  attachments(0) = "c:\temp\any_file.txt"
  imageFiles(0) = "c:\temp\any_jpeg.jpg"
  imageTypes(0) = "image/jpg"
  imageTags(0) = "any_jpeg.jpg"
  Call ComposeMemo("some.user@acme.com", "Test from Excel", html, attachments, imageFiles, imageTypes, imageTags)
 
End Sub
 
Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String, imageFiles() As String, imageTypes() As String, imageTags() As String)
 
  Dim sess As Object, db As Object, doc As Object, stream As Object, ws As Object, uidoc As Object
  Dim mimeBody As Object, mimeHtml As Object, mimeFile As Object, mimeImage As Object, mimeHeader As Object
  Dim i As Integer
  Dim convertMime As Boolean
  Const ENC_QUOTED_PRINTABLE = 1726
  Const ENC_IDENTITY_8BIT = 1729
  Const EMBED_ATTACHMENT = 1454
 
  ' Create an email doc
  Set sess = CreateObject("Notes.NotesSession")
  Set ws = CreateObject("Notes.NotesUiWorkspace")
  Set db = sess.GetDatabase("", "")
  Call db.OpenMail
  Set doc = db.CreateDocument()
  Call doc.ReplaceItemValue("Form", "Memo")
 
  ' add the body as a mime html part
  convertMime = sess.convertMime
  sess.convertMime = False
  Set stream = sess.CreateStream()
  stream.WriteText (html & "<br><br>")
  Set mimeBody = doc.CreateMIMEEntity("Body")
  Set mimeHtml = mimeBody.CreateChildEntity()
  Call mimeHtml.SetContentFromText(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
  Call stream.Close
  
  ' add file attachments
  For i = 0 To UBound(attachments)
    Set mimeFile = mimeBody.CreateChildEntity()
    Set mimeHeader = mimeFile.CreateHeader("Content-Transfer-Encoding")
    Call mimeHeader.SetHeaderVal("binary")
    Set mimeHeader = mimeFile.CreateHeader("Content-Disposition")
    Call mimeHeader.SetHeaderVal("attachment; filename=" & attachments(i))
    Call stream.Open(attachments(i), "binary")
    Call mimeFile.SetContentFromBytes(stream, "text/plain", ENC_NONE)
    Call mimeFile.EncodeContent(ENC_IDENTITY_8BIT)
    Call stream.Close
  Next
  
  ' add images referenced by cid tags
  For i = 0 To UBound(imageFiles)
    Set mimeImage = mimeBody.CreateChildEntity()
    Set mimeHeader = mimeImage.CreateHeader("Content-ID")
    Call mimeHeader.SetHeaderVal("<" & imageTags(i) & ">")
    Call stream.Open(imageFiles(i))
    Call mimeImage.SetContentFromBytes(stream, imageTypes(i) & "; name=" + imageTags(i), ENC_IDENTITY_BINARY)
    Call stream.Close
  Next
  
  sess.convertMime = convertMime
  Call doc.CloseMIMEEntities(True, "Body")
  Call doc.Save(True, False)
  Set uidoc = ws.EditDocument(True, doc)
  Call doc.Remove(True)
  ' Exit Sub ' if you don't need the user's signature, you can exit here, otherwise...
  Call uidoc.GotoField("Body")
  Call uidoc.SelectAll
  Call uidoc.Copy
  uidoc.Document.SaveOptions = "0"
  uidoc.Document.MailOptions = "0"
  Call uidoc.Close
  
  ' compose a new memo and paste the body.
  Set uidoc = ws.ComposeDocument(db.Server, db.filePath, "Memo")
  Call uidoc.FieldSetText("EnterSendTo", sendto)
  Call uidoc.FieldSetText("Subject", subject)
  Call uidoc.GotoField("Body")
  Call uidoc.Paste
 
End Sub

Open in new window

Avatar of Hammer8

ASKER

Bill - thank you for your continued help.  I tried the new code but the jpg file does not display properly.  The email shows up with an empty box before the bold text "This is a test!" and on the line below is the attached file (with the proper icon) and a blank icon for the jpg file.  I also get an IBM Lotus Notes message box which says "Cannot copy bitmap to disk" with just an ok button.  Any thoughts?  Does this code work on your setup?  Thanks again!  Hammer8
Avatar of Hammer8

ASKER

Also, the note also does not display properly when sent to Outlook.  I see the test and 2 attached files which are in the body of the email (versus in the attachment section at the top of the email).  
>> "The email shows up with an empty box"

Forgive me, but are you sure that the JPEG referenced in the code exists on your hard drive in the correct location?  I don't think this is the problem, but it doesn't hurt to check, right?

Also, if you changed the file name in the code, you may also have changed the imageTags(0) variable.  If you did, then you also have to change the HTML CID tag to the same value you set for imageTags(0).  If the CID tags do not match, then the result is exactly what you describe above (except for the message box).

FYI: the CID values are what link the IMG tags in the HTML to the files stored in MIME.  The CID value does not need to be the name of the file being embedded, but it should have the correct extension so that it will be displayed correctly.  Sometimes in my code, I simply name the CID tags sequentially regardless of the actual file names (1.jpg, 2.jpg, 3.jpg, etc).

>> "Does this code work on your setup?"

Yes.

>> "the note also does not display properly when sent to Outlook"

This could be a router setting on either end.  It's hard to say how mime will be interpreted once it leaves your router.  Most mass email clients will not use inline images for this reason.  They simply host the images on a web server, then use standard IMG tags.
Avatar of Hammer8

ASKER

Thanks for not giving up on me...I tried it with a jpg file and it works in Notes, but still the image do not display in Outlook - I think I will just live with that.  By the way, do you know what the "image/jpg" equivalent is for GIF's?  I used "image/GIF" and that's why I think the code didn't work the first time around.  My images are GIF's and not jpg's.  Thanks!
>> "Thanks for not giving up on me"

No problem.  This is helping to hone my mime skills, so we both win!

>> "By the way, do you know what the "image/jpg" equivalent is for GIF's?"

Yes, it is "image/gif".

>> "I used "image/GIF" and that's why I think the code didn't work the first time around."

If you change the MIME entity's content type to GIF, make sure that you also change the HTML IMG's content id (cid) to GIF.

Notice in the example below that I changed the IMG's cid and the imageTags(0) variable to "image_1.gif".  I also changed the imageFiles(0) variable to point to a valid GIF file and the imageTypes(0) variable now specifies the "image/gif" content type.  The important thing to remember here is that the file type must match in all four locations in the code (HTML, imageFiles, imageTypes, and imageTags).  Also, the IMG tag's cid must match the imageTags variable exactly.

I have tested this code with GIF files as well as JPEGs, so if you ensure that the file type matches in all four places, the code should work for you too.
Sub Test_GIF()
 
  Dim html As String
  Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
  html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:image_1.gif'>This is a test!</div>"
  attachments(0) = "c:\temp\any_file.txt"
  imageFiles(0) = "c:\temp\any_image.gif"
  imageTypes(0) = "image/gif"
  imageTags(0) = "image_1.gif"
  Call ComposeMemo("some.user@acme.com", "Test from Excel", html, attachments, imageFiles, imageTypes, imageTags)
 
End Sub

Open in new window

Avatar of Hammer8

ASKER

Thanks.  Happy New Year!  Hammer8
Avatar of Hammer8

ASKER

Bill, sorry to bug you again, but do you have a quick fix for this?  Using the code above, since the email is left open for the user to edit, once the editing is done and we go and hit send, we get the message:  Another copy of this document was saved while you were editing it.  Save your changes also as a Save Conflict document?  What does this mean and how can I avoid this?  Thank you again...
No problem.

>> "Save your changes also as a Save Conflict document?  What does this mean and how can I avoid this?"

This means that something saved the back-end document while the front-end document was opened for editing.  Using the code above, this should not be possible since we ensure that the back-end document is deleted whenever the front-end document is displayed.  The order of operations in the code above is very important; especially lines 67-69.

I also noticed a problem while testing this code.  If I allow the code to exit on line 70, I get a different error message when I go to send the memo ("One or more of the source document's attachments are missing.  Run Fixup to delete the document in the source database: mail.box").  So it's probably a good idea to let the code run to the end.
Avatar of Hammer8

ASKER

Bill, it's been a while and the code you helped me with back in 2009 has worked perfectly over the past few years so thank you for that!  

Unfortunately, my desktop got rebuilt last weekend and all my apps including Office and Notes were reinstalled.  Now, when I run that same code, I get a run-time error 91: Object variable or With block variable not set at line 71 of ComposeMemo: Call uidoc.GotoField("Body")

Can I trouble you again?

Thank you.