variable value in the email body
-
2012年4月30日 13:30
Hi, I have below lines of code which reads a text file and will keep a value under the variable "total". Now, I want to send the value which is stored in the variable "total" by email.
In below code i have added the total variable to "strMessage2" variable and send it as a parameter to SendMail function so that it will come under email body.But, It is sending email without considering the value of total variable. how can i do it? Also, how can make total value to appear in bold letters in the email content.
*****************************************************************Set fso = CreateObject("Scripting.FileSystemObject")
Set inFile = fso.OpenTextFile("myfile.txt")
Set outFile = fso.OpenTextFile("output.txt", 2, True)
While Not inFile.AtEndOfStream
line=inFile.ReadLine()
If InStr(line, "TOTAL:") Then
a = split(line," ")
total = a(UBound(a))
End If
WendinFile.Close
outFile.Close
strMessage2 = "Live Floor View Code Count is: " & totalSendMail strFrom,strTo,strSubject2,strMessage2,strAccountID,strPassword,strSMTPServer
*****************************************************************
- 編集済み prabasb 2012年4月30日 13:31
すべての返信
-
2012年4月30日 14:14
from your code, it appears you have concatenated the variable (total) to strMessage2 properly. However, looking at your file-reading loop, you're splitting each line by a space-character. Are you sure there are NO trailing spaces at the end of the line? if so, the upper bound of the line would be blank which could be why you aren't seeing the value of the variable (total) in your output.
As an example:
"This is a string "
Notice the trailing space at the end of the line. If you split by a space-character and then just take the upper bound of the resulting array, it would be blank.
- 編集済み thepip3r 2012年4月30日 14:26
-
2012年4月30日 14:20モデレータ
And the solution in such a case is to TRIM() the string before SPLITing it ...
a = split(Trim(line)," ")
Tom Lavedas
- 回答の候補に設定 Richard MuellerMVP, Moderator 2012年4月30日 15:55
- 回答としてマーク IamMredMicrosoft Employee, Owner 2012年5月7日 0:17
-
2012年4月30日 15:57
Another quick way out of this dilemma.
If InStr(line, "TOTAL:") Then
a = split(line," ")
total = Replace(line."TOTAL:","")
End IfThis will jsut remove the offending word and leave the remainder of teh line to be sent.
¯\_(ツ)_/¯
-
2012年4月30日 18:11
Thank you. i want to send three fileds values (inlcuding with above total variable value) in a tabler format while sending the email. is there any way to do it? please suggest.
-
2012年4月30日 19:00
Thank you. i want to send three fileds values (inlcuding with above total variable value) in a tabler format while sending the email. is there any way to do it? please suggest.
strMessage = strMessage & vbTab & variable1 & vbTab & variable2 & vbTab & variable3 & vbTab & variable4
Like that?
What do you mean "tabler"? Tabular? Like a web page?
¯\_(ツ)_/¯
-
2012年5月4日 14:45
I am trying to send email using ".HTMLBody" method through CDO object, my code looks like below
.HTMLBody = Message
Now, i have addeded below code to above "Message" variable to send a HTML table with two colums and two rows as the email message body, but it is not working as expected.
Mesage = <table border="1"> <tr title="You are looking at Row 1" bgcolor="silver"> <td>Row 1 Cell 1</td> <td>Row 1 Cell 2</td> </tr> <tr title="You are looking at Row 2" bgcolor="aqua"> <td>Row 2 Cell 1</td> <td>Row 2 Cell 2</td> </tr> </table>
-
2012年5月4日 15:02
Message = "<table border='1'> <tr title='You are looking at Row 1' bgcolor='silver'> <td>Row 1 Cell 1</td> <td>Row 1 Cell 2</td> </tr> <tr title='You are looking at Row 2' bgcolor='aqua'> <td>Row 2 Cell 1</td>XXXTOTALXXX<td>Row 2 Cell 2</td> </tr> </table>"
Message was spelled wrong.
It is easier to design HTML with an HTML editor. Always use single quotes so string can be wrapped in an outer quote.
Place variable placeholder in file or string.
message = Replace(message,"XXXTOTALXXX", total)
This will put the total into the string before sending. The XXXs are to make sure the placeholder is unigue.
¯\_(ツ)_/¯

