Consulting

Results 1 to 3 of 3

Thread: Non Default Signature

  1. #1

    Non Default Signature

    Hi everyone,

    I am trying to create an e-mail that pulls a signature of my choice (DesSig in this instance). I am using an example from info@learnexcelmacro.com. Anyway I am getting a "Run-time error 91, Object Variable or With block variable not set"

    The error is throwing half way down at StrSignature = GetSignature(sPath)

    There was no variable declared in the example for GetSignature so I declared it as an object, which I am presuming is incorrect.

    Here is the full code

    Sub With_HTML_Signature()
      
        'Do not forget to change the email ID
        'before running this code
      
        Dim OlApp As Object
        Dim NewMail As Object
        Dim EmailBody As String
        Dim StrSignature As String
        Dim sPath As String
        Dim GetSignature As Object
      
        Set OlApp = CreateObject("Outlook.Application")
        Set NewMail = OlApp.CreateItem(0)
          
        ' Here Since we are talking about
        ' the HTML email then we need to
        ' write the Body of the Email in
        ' HTML.
      
        EmailBody = "Hello Friends !!" & "<br><br>Welcome to LearnExcelMacro.com" & vbNewLine & _
        "Here i will make you awesome in Excel Macro.<br><br>You can mail me at info@learnexcelmacro.com"
      
        '*****************************************************
        '                    Important
        '*****************************************************
        ' go to the appdata path as mentioned in
        ' the above important point. Check the name of
        ' the signature file. For example: here in my system
        ' the signature's file name is vish.txt, vish.htm
        ' Therefore before running this code, check the
        ' name fo the signature file in your system and
        ' replace vish.txt with your file name.
        '****************************************************
      
        sPath = Environ("appdata") & "\Microsoft\Signatures\DesSig.htm"
      
        ' If the path and file name given by you is not
        ' correct then code you insert a blank Signature
          
        If Dir(sPath) <> "" Then
            StrSignature = GetSignature(sPath)
            
        Else
            StrSignature = ""
        End If
      
        On Error Resume Next
        With NewMail
            .To = "info@learnexcelmacro.com"
            .CC = "info@learnexcelmacro.com"
            .BCC = "info@learnexcelmacro.com"
            .Subject = "Type your Subject here"
            ' Here at the end of the Email Body
            ' HTML Signature is inserted.
            .htmlBody = EmailBody & "<br><br>" & StrSignature
            '.send
            .display
        End With
        On Error GoTo 0
        Set NewMail = Nothing
        Set OlApp = Nothing
    End Sub

  2. #2
    GetSignature is not a variable. It's a call to a function, which presumably you didn't copy along with the rest of the macro.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Quote Originally Posted by gmayor View Post
    GetSignature is not a variable. It's a call to a function, which presumably you didn't copy along with the rest of the macro.

    Thanks very much for the response GMayor. You are exactly correct. GetSignature is a function that was posted separately to the main sub (I should have seen it if I opened my eyes!!). Here is the Function and full Sub in question if anyone needs it.

    Note: It will not display an image if it is part of your signature. I am marking this thread as solved.

    Function GetSignature(fPath As String) As String
        Dim fso As Object
        Dim TSet As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)
        GetSignature = TSet.readall
        TSet.Close
    End Function
    
    
    
    
    Sub With_HTML_Signature()
      
        'Do not forget to change the email ID
        'before running this code
      
        Dim OlApp As Object
        Dim NewMail As Object
        Dim EmailBody As String
        Dim StrSignature As String
        Dim sPath As String
        
      
        Set OlApp = CreateObject("Outlook.Application")
        Set NewMail = OlApp.CreateItem(0)
          
        ' Here Since we are talking about
        ' the HTML email then we need to
        ' write the Body of the Email in
        ' HTML.
      
        EmailBody = "Hello Friends !!" & "<br><br>Welcome to LearnExcelMacro.com" & vbNewLine & _
        "Here i will make you awesome in Excel Macro.<br><br>You can mail me at info@learnexcelmacro.com"
      
        '*****************************************************
        '                    Important
        '*****************************************************
        ' go to the appdata path as mentioned in
        ' the above important point. Check the name of
        ' the signature file. For example: here in my system
        ' the signature's file name is vish.txt, vish.htm
        ' Therefore before running this code, check the
        ' name fo the signature file in your system and
        ' replace vish.txt with your file name.
        '****************************************************
      
        sPath = Environ("appdata") & "\Microsoft\Signatures\DesSig.htm"
      
        ' If the path and file name given by you is not
        ' correct then code you insert a blank Signature
          
        If Dir(sPath) <> "" Then
            StrSignature = GetSignature(sPath)
            
        Else
            StrSignature = ""
        End If
      
        On Error Resume Next
        With NewMail
            .To = "info@learnexcelmacro.com"
            .CC = "info@learnexcelmacro.com"
            .BCC = "info@learnexcelmacro.com"
            .Subject = "Type your Subject here"
            ' Here at the end of the Email Body
            ' HTML Signature is inserted.
            .htmlBody = EmailBody & "<br><br>" & StrSignature
            '.send
            .display
        End With
        On Error GoTo 0
        Set NewMail = Nothing
        Set OlApp = Nothing
    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
  •