如何用VB发邮件的内容保持原来的格式
就是我用OUTLOOK里面的Visul Basic编程,想要群发邮件,邮件的内容有加粗了,变红等格式。如何群发邮件的时候,保持原格式不变呢?我用了.HTMLBody = strBody ,发现在原来的格式还是没有了。
还有怎么在邮件的内容里面加上一个变量,随着我每封邮件收件人的不同而变化。
大概就是这样一个格式:主题:xxx通知
内容:你好,据系统查询你是(变量)的管理员,请在下周四之前回复!
我原来没有学过VB的,只接触过C语言,还请各位大侠解说的仔细一点,谢谢啦~
我搜到了一份源代码跟我要求很相近了,但是我不会改
Public Function SendMail(strFrom As String, strTo As String, _
strCC As String, _
strBCC As String, _
strSubject As String, _
strBody As String, _
strFilename As String _
) As Boolean
Dim oOutlookApp As New Outlook.Application
Dim oItemMail As Outlook.MailItem
Set oItemMail = oOutlookApp.CreateItem(olMailItem)
On Error GoTo errHandle
If Len(Trim(strFilename)) = 0 Then
With oItemMail
'.Recipients
.SentOnBehalfOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.Body = strBody
'.Attachments.Add (strFilename)
.Importance = olImportanceHigh
.Sensitivity = olPersonal
.Send
End With
Else
With oItemMail
'.Recipients
.SentOnBehalfOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.Body = strBody
.Attachments.Add (strFilename)
.Importance = olImportanceHigh
.Sensitivity = olPersonal0
.Send
End With
End If
SendMail = True
Exit Function
errHandle:
SendMail = False
End Function
Public Function CheckMail(strFrom As String, strTo As String, _
strCC As String, _
strBCC As String, _
strSubject As String, _
strBody As String, _
strFilename As String _
) As Boolean
Dim oOutlookApp As New Outlook.Application
Dim oItemMail As Outlook.MailItem
Set oItemMail = oOutlookApp.CreateItem(olMailItem)
On Error GoTo errHandle
If Len(Trim(strFilename)) = 0 Then
With oItemMail
'.Recipients
.SentOnBehalfOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.HTMLBody = strBody
'.Attachments.Add (strFilename)
.Importance = olImportanceHigh
.Sensitivity = olPersonal
.Display
End With
Else
With oItemMail
'.Recipients
.SentOnBehalfOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.HTMLBody = strBody
.Attachments.Add (strFilename)
.Importance = olImportanceHigh
.Sensitivity = olPersonal
.Display
End With
End If
CheckMail = True
Exit Function
errHandle:
CheckMail = False
End Function
Sub SendMailNow()
Dim ExcelSheet As Object
Dim rowCount As Integer
Dim i As Integer
Set ExcelSheet = CreateObject("c:\email.xls")
rowCount = ExcelSheet.sheets(1).UsedRange.Rows.Count
For i = 2 To rowCount
SendMail strFrom:=ExcelSheet.sheets(1).cells(i, 1), strTo:=ExcelSheet.sheets(1).cells(i, 2), _
strCC:=ExcelSheet.sheets(1).cells(i, 3), strBCC:=ExcelSheet.sheets(1).cells(i, 4), _
strSubject:=ExcelSheet.sheets(1).cells(i, 5), strBody:=ExcelSheet.sheets(1).cells(i, 6), _
strFilename:=ExcelSheet.sheets(1).cells(i, 7)
Next i
ExcelSheet.Close False
Set ExcelSheet = Nothing
End Sub
Sub CheckMailNow()
Dim ExcelSheet As Object
Dim rowCount As Integer
Dim i As Integer
Set ExcelSheet = CreateObject("c:\email.xls")
rowCount = ExcelSheet.sheets(1).UsedRange.Rows.Count
For i = 2 To rowCount
CheckMail strFrom:=ExcelSheet.sheets(1).cells(i, 1), strTo:=ExcelSheet.sheets(1).cells(i, 2), _
strCC:=ExcelSheet.sheets(1).cells(i, 3), strBCC:=ExcelSheet.sheets(1).cells(i, 4), _
strSubject:=ExcelSheet.sheets(1).cells(i, 5), strBody:=ExcelSheet.sheets(1).cells(i, 6), _
strFilename:=ExcelSheet.sheets(1).cells(i, 7)
Next i
ExcelSheet.Close False
Set ExcelSheet = Nothing
End Sub
[ 本帖最后由 haiyanzi2005 于 2012-9-17 10:54 编辑 ]