quick87
(/ội...
- Tham gia
- 8/4/08
- Bài viết
- 371
- Được thích
- 351
- Giới tính
- Nam
Kính gửi: các Thầy, các anh chị.
Em có vọc được một đoạn code gửi mail tự động bằng excel và có chỉnh sửa một chút cho phù hợp với công việc thực tế của mình, nội dung cụ thể:
Vấn đề em đang bị vướng ở đây:
Em có vọc được một đoạn code gửi mail tự động bằng excel và có chỉnh sửa một chút cho phù hợp với công việc thực tế của mình, nội dung cụ thể:
PHP:
Private Sub CommandButton1_Click()
Dim Flds
Dim rng As Range
Dim iMsg As New CDO.Message
Dim iConf As New CDO.Configuration
Set Flds = iConf.Fields
Set rng = Sheets("Sheet1").Range("B1:I22").SpecialCells(xlCellTypeVisible)
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = cdoSendUsingPort
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "" 'Dia chi that
Flds.Item(schema & "sendpassword") = "" 'Pass that
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
With iMsg
.To = Range("K4").Value 'tuy y
.CC = Range("K5").Value
.BCC = ""
'.AddAttachment ("") 'Dia chi file phai ton tai
.From = "<" & "pquick87@gmail.com" & ">" 'tuy y
.Subject = Range("K6").Value 'tuy y
.HTMLBody = RangetoHTML(rng)
Set .Configuration = iConf
.Send
End With
MsgBox "Mail sent done.."
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2013
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
Vấn đề em đang bị vướng ở đây:
- Khi xem mail trên Outlook thì ok: các khung table vẫn giữ được đúng định dạng, nhưng khi xem mail trên Firefox, Internet Explorer thì mail lại bị mất định dạng như hình phía dưới:
- Khi xem trên Outlook:
- Khi xem trên Firefox:
Vậy, code em phải chỉnh như thế nào để khi xem mail trên Firefox hoặc Internet Explorer, các trình duyệt khác thì mail vẫn giữ nguyên được định dạng như xem mail trên Outlook ạ !
Kính mong các Thầy, các anh chị giúp đỡ.
Em xin chân thành cảm ơn !
File đính kèm
Lần chỉnh sửa cuối: