我每天发送一封电子邮件。它主要是来自网站的复制粘贴,以前可以使用。
我现在的形状在我希望包含在电子邮件中的范围内。
这是第一个看起来不错的部分。
function checkB(array, i, j) {
return i in array && array[i][j] === 'B';
}
// call
if (checkB(grid, cx, cy - 1)) numb++;
这是麻烦所在。
Sub Send_EOS()
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
Set rng = Sheets("Wash").Range("B2:H98").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Sheets("Settings").Range("E31")
.CC = Sheets("Settings").Range("E32")
.BCC = ""
.Subject = "" & Sheets("Shift Plan").Range("V3") & " " & Sheets("Shift Plan").Range("V7") & " Shift Wash"
.HTMLBody = RangetoHTML(rng)
.send
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
我认为Function RangetoHTML(rng As Range)
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"
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
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
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=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
可能正在删除对象,但是删除并不能解决问题。
我还认为.DrawingObjects.Delete
可能正在这样做,所以我将其更改为粘贴所有内容,但没有用。
我还尝试了不要在最后删除临时文件,也不要清除剪贴板以查看副本是否有问题,但是当我自己粘贴时,形状转移了,但是临时文件没有显示对象
我也尝试了所有这些事情,但是没有运气。