Consulting

Results 1 to 3 of 3

Thread: Error Trying to send email via Excel

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    14
    Location

    Error Trying to send email via Excel

    I had a piece of code that was working perfectly, then something happened after my Laptop rebooted and now I am getting an Object Variable with Block Variable not Set

    for the life of me I cannot seem to figure out where the issue is coming from

    Thoughts ?

    Option Explicit
     
    Const EMBED_ATTACHMENT As Long = 1454
    
    Const stPath As String = ""
    
    Const stSubject As String = ""
    
    Const vaMsg As Variant = ""
                                               
    Sub Send_Active_Sheet()
     
      Dim stFileName As String
      Dim vaRecipients As Variant
     
      Dim noSession As Object
      Dim noDatabase As Object
      Dim noDocument As Object
      Dim noEmbedObject As Object
      Dim noAttachment As Object
      Dim stAttachment As String
      
    
        stAttachment = stPath & wsOrig.Range("c5").Value & ".xls"
     
      '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 noAttachment = noDocument.CreateRichTextItem("stAttachment")
      Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
     
      'Add values to the created e-mail main properties.
      With noDocument
        .Form = "Memo"
        .SendTo = vaRecipients
        '.CopyTo = vaCopyTo
        .subject = stSubject
        .Body = vaMsg
        .SaveMessageOnSend = True
        .PostedDate = Now()
        .Send 0, vaRecipients
      End With
     
      'Delete the temporarily workbook.
      Kill stAttachment
     
      'Release objects from memory.
      Set noEmbedObject = Nothing
      Set noAttachment = Nothing
      Set noDocument = Nothing
      Set noDatabase = Nothing
      Set noSession = Nothing
     
      MsgBox "The e-mail has successfully been created and distributed", vbInformation
     
    End Sub

  2. #2
    VBAX Regular
    Joined
    Dec 2011
    Posts
    14
    Location
    Figured out the error of my ways, somehow the following got deleted

    'Instantiate the Lotus Notes COM's Objects.
    Set noSession = CreateObject("Notes.NotesSession")
    Set noDatabase = noSession.GETDATABASE("", "")

    Now new issue is Notes is now crashing on send attempt

  3. #3
    VBAX Regular
    Joined
    Dec 2011
    Posts
    14
    Location
    The issue is with
    .Send 0, vaRecipients

    I dumbed it down to a direct link to an already existing file and it works (Below) , So I suspect that it might have something to do with how the stAttachment is being represented in the larger automated process, but I don't see an error anywhere when walking through it

    Anyone have any thoughts?



    Option Explicit
     
    Const EMBED_ATTACHMENT As Long = 1454
    
    Const stPath As String = "D:\abc123.xls"
    
    Const stSubject As String = "whatever"
    
    Const vaMsg As Variant = "whatever"
                                               
    Sub Test_send()
     
      Dim stFileName As String
      Dim vaRecipients As Variant
     
      Dim noSession As Object
      Dim noDatabase As Object
      Dim noDocument As Object
      Dim noEmbedObject As Object
      Dim noAttachment As Object
      Dim stAttachment As String
      
      Dim wsOrig As Worksheet
      Dim wsTemp As Worksheet
      Dim wsNew As Worksheet
      Dim wsNew2 As Worksheet
      Dim wbNew As Workbook
      Dim rng As Range
      Dim wsOrig2 As Worksheet
        
    
        stAttachment = "D:\ABC123.xls"
     vaRecipients = "me@me.com"
     
       '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 noAttachment = noDocument.CreateRichTextItem("stAttachment")
      Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
     
      'Add values to the created e-mail main properties.
      With noDocument
        .Form = "Memo"
        .SendTo = vaRecipients
        '.CopyTo = vaCopyTo
        .subject = stSubject
        .Body = vaMsg
        .SaveMessageOnSend = True
        .PostedDate = Now()
        .send 0, vaRecipients
    
      End With
     
      'Delete the temporarily workbook.
      Kill stAttachment
     
      'Release objects from memory.
      Set noEmbedObject = Nothing
      Set noAttachment = Nothing
      Set noDocument = Nothing
      Set noDatabase = Nothing
      Set noSession = Nothing
     
      MsgBox "The e-mail has successfully been created and distributed", vbInformation
     
    End Sub

Posting Permissions

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