我想在Outlook中粘贴一系列单元格。
这是我的代码:
我没有收到任何错误提示,只是无法在Outlook中粘贴范围。
我已经删除了
这是我的代码:
Sub Mail_Selection_Range_Outlook_Body()
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
' Only send the visible cells in the selection.
Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set rng = Sheets("Sheet1").RangeToHtml("D4:D12").SpecialCells(xlCellTypeVisible, xlTextValues)
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 = ThisWorkbook.Sheets("Sheet2").Range("C1").Value
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = RangeToHtml.rng
' In place of the following statement, you can use ".Display" to
' display the e-mail message.
.Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
我没有收到任何错误提示,只是无法在Outlook中粘贴范围。
我已经删除了
On Error Resume Next
。它给了我一个错误提示:
对象不支持此属性或方法。
Set rng = Sheets("Sheet1").RangeToHtml("D4:D12").SpecialCells(xlCellTypeVisible, xlTextValues)
看起来有问题。假设RangeToHtml
是从微软网站上的函数,它返回的是一个字符串,因此你不能在该字符串上调用SpecialCells
。去掉On Error Resume Next
,你就会看到错误提示。 - Tim WilliamsOn Error Resume Next
。 - enderland