質問

I am using the following code to place and email in the Pickup directory of our SMTP server. Currently the entire file is composed inline. I would like to be able to use a template file wile place holders for the values to create the file since we are going to use HTML and want to change the email sometimes.

Dim objFSO 'As FileSystemObject
Dim objTextFile 'As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("\\CampSaverS2\inetpub\mailroot\Pickup\"&rs.fields("OrderNumber")&".txt")

'rs.fields("OrderNumber") calls the order number, rs.fields("Name") calls customer name, app.S.get("Tracking_Number") calls tracking, rs.fields("email") for email

objTextFile.Write("to:"&rs.fields("email")& vbCrLf &_
"from:adsitest@campsaver.com"& vbCrLf &_
"subject:Tracking Test"& vbCrLf &_
"MIME-Version: 1.0"& vbCrLf &_
"Content-Type: text/html; charset=”iso-8859-1"& vbCrLf &_
"Content-Transfer-Encoding: quoted-printable"& vbCrLf &_
'HTML will go here
"Test email <br> Tracking info for order " & rs.fields("OrderNumber") & " is " & app.S.get("Tracking_Number") & vbCrLf & "Sent From ADSI.")
objTextFile.Close
役に立ちましたか?

解決

You should be able to adapt this for your needs:

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTemplateTS
Const ForReading = 1
Set objTemplateTS = objFSO.OpenTextFile("C:\MyTemplate.txt", ForReading, False)
Dim strAllTemplateText
strAllTemplateText = objTemplateTS.ReadAll()
objTemplateTS.Close()
strAllTemplateText = Replace(strAllTemplateText, "<Placeholder_One>", "My First New Value")
strAllTemplateText = Replace(strAllTemplateText, "<Placeholder_Two>", "My Second New Value")
Dim objOutputTS
Const ForWriting = 2
Set objOutputTS = objFSO.OpenTextFile("C:\Output.txt", ForWriting, True)
objOutputTS.Write(strAllTemplateText)
objOutputTS.Close()
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top