如何仅在VBA中设置可见单元格的范围?

时间:2019-01-21 17:24:25

标签: excel vba

我有一个功能,可以将具有选定范围的电子邮件设置为电子邮件正文。但是,尽管所选范围具有隐藏行,但是复制的范围具有所有行。有没有办法只复制可见的?我尝试使用SpecialCells(xltypeVisibleOnly),但没有成功。有什么建议吗?

Sub Button6_Click()

Dim dt As Date
Dim rBody(0) As Range
Dim b As Boolean

dt = [RefDate]

With shtDash
    Set rBody(0) = .Range("Print_Mail")
End With

b = SendMail(rBody, "subject" & dt, [to_mail], [cc_mail])

If Not b Then
    MsgBox "Error running mail macro. Please debug."
End If

End Sub

编辑:我尝试设置.Range(“ Print_Mail”)。SpecialCells(xlCellTypeVisible),但它不起作用。 b返回false。需要说明的是,由于SendMail函数的编码方式,rBody必须是一个范围。

0 个答案:

没有答案