Results 1 to 10 of 10

Thread: Send Lotus Notes email with attachment via VBA

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,886
    Location
    1. The commented out line ...



    'Set notesEmbedObject = notesAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)

    … was because of a note I found

    'http://www.fabalou.com/VBandVBA/lotusnotesmail.asp 'Point of note. Certain versions of 4.x client handle differently. 'If you get an error on the line MailDoc.CREATERICHTEXTITEM ("Attachment"), then 'try removing that line. In later versions of notes API this task is carried out by the 'previous line. Earlier versions required the call afterwards 'if it doesn't work comment out this line '--------------------------------------------------------------------------------------------
    2. The driver sub creates the test workbook so the
    SendWithLotus should always find it

    3. The latest grope in the dark ….

    Option Explicit
    
    'https://www.rondebruin.nl/win/s1/notes/notes4.htm
    
    Sub SendWithLotusNew(Subject As String, Attachment As String, Recipient As String, BodyText As String)
       Dim noSession As Object, noDatabase As Object, noDocument As Object
       Dim obAttachment As Object, EmbedObject As Object
     
       Const EMBED_ATTACHMENT As Long = 1454
       
       'Instantiate the Lotus Notes COM's Objects.
       Set noSession = CreateObject("Notes.NotesSession")
       Set noDatabase = noSession.GETDATABASE("", "")
     
       'If Lotus Notes is not open then open the mail-part of it.
       If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
     
       'Create the e-mail and the attachment.
       Set noDocument = noDatabase.CreateDocument
       Set obAttachment = noDocument.CreateRichTextItem("Attachment")
       Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", Attachment)
     
       'Add values to the created e-mail main properties.
       With noDocument
          .Form = "Memo"
          .SendTo = Recipient
          .Subject = Subject
          .Body = BodyText
          .SaveMessageOnSend = True
       End With
     
       'Send the e-mail.
       With noDocument
          .PostedDate = Now()
          .Send 0, Recipient
       End With
     
       'Release objects from the memory.
       Set EmbedObject = Nothing
       Set obAttachment = Nothing
       Set noDocument = Nothing
       Set noDatabase = Nothing
       Set noSession = Nothing
     
     End Sub

    Still no joy
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Could be a file creation timing issue?

    After the Dim lines, I would check for it anyway. Normally, one might just do the Set for Attachment object if the file did exist. In this case, I would use this method though as a debug tool.

      If Dir(Attachment) = "" Then    
         MsgBox Attachment, vbCritical, "File Does Not Exist - Macro Ending!"
        Exit Sub
      End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •