dodonohoe
06-22-2016, 01:46 AM
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
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