如何将.htm文件的内容添加到字符串?

时间:2021-05-26 07:37:07

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.

我想将默认签名添加到从Excel中的Userform发送的电子邮件的末尾。但是,由于正文是HTML(因为我无法更改),因此它不会显示签名。

I have the following code that is the location of the default.htm signature:

我有以下代码,它是default.htm签名的位置:

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

我现在需要做的(并且遇到问题)是将此default.htm文件的内容添加到电子邮件正文的末尾。但是,做

.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?

如何让它插入HTML文件的内容?

2 个解决方案

#1


1  

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

#2


1  

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

#1


1  

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

#2


1  

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