How do I add the contents of a .htm file to a string?
-
21-12-2019 - |
Question
I want to add the default signature to the end of an email that is being sent from a Userform in Excel. However, due to the body being HTML (for reason I cannot change) the signature it not displaying.
I have the following code that is the location of the default.htm signature:
strSig = Environ("AppData") & "\Microsoft\Signatures\Default.htm"
What I now need to do (and am having issues with) is add the contents of this default.htm file to the end of the body of the email. However, doing
.HTMLBody = "some text <br>" & strSig
it just adds the location path in text form to the email.
How do I get it to insert the contents of the HTML file?
Solution
Here's a way to do it
Dim FSO As Object : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim strSig As String
Dim pthSig As String
pthSig = Environ("AppData") & "\Microsoft\Signatures\Default.htm"
strSig = FSO.OpenTextFile(pthSig).ReadAll ' signature content
.HTMLBody = "some text <br>" & strSig
OTHER TIPS
You need to read the file content from the path first.
Dim ff As Integer, sigTxt as String
ff = FreeFile
Open strSig For Input As #ff
sigTxt = Input$(LOF(1), 1)
Close
.HTMLBody = sigTxt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow