|
谁能看懂这段代码? 求助
Private Sub CommandButton21_Click()
Dim cell As Range
Dim c As Range
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String, MailSub As String, MailTxt As String, MailTo As String, MailCC As String
Dim t As TableObject
Dim rng As Range
Dim rng1 As Range
Dim rng2 As Range
Dim i, j, k As Integer
Dim lrow As Long
MailTo = "aaa@gda.com"
MailCC = "aab@gda.com"
MailSub = "demande de modifier la productivité 11/20/2014"
MailTxt = vbNewLine & "Request for change in productivity information"
Application.ScreenUpdating = False
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.To = MailTo
.Cc = MailCC
'.Bcc = MailBCC
.Subject = MailSub
Set rng = Sheets(2).Range("L09:P109")
'Set rng2 = Sheets(3).Range(Range("A1"), Range("A1").End(xlDown).End(xlToRight))
.HTMLBody = MailTxt & RangetoHTML(rng) & vbNewLine & "For clarification, please send an email to gowri@"
.send
End With
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
Application.DisplayAlerts = False
Application.DisplayAlerts = True
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
|
|