发送HTML电子邮件范围

时间:2016-08-31 13:42:48

标签: vba excel-vba html-email excel

我有以下脚本设置要复制到电子邮件的范围但是我要求此范围从第1列到第13列,同时删除第7列(“1:6”,“8:13”) 我已尝试过各种方法来纠正这种情况,但每次尝试都会导致错误。

这是我正在使用的代码

Set RangeCopy = Sheets("Applications").Range(Cells(1, 1), Cells(R, 13)).SpecialCells(xlCellTypeVisible)

感谢任何帮助。 谢谢。

3 个答案:

答案 0 :(得分:2)

使用Union是非常干净的方法。请参阅下面的代码中的编码示例。

    Dim unionrng As Range
    Set unionrng = Application.Union(Sheets("Applications").Range(Cells(1, 1), Cells(r, 6)), _
                                     Sheets("Applications").Range(Cells(1, 8), Cells(r, 13)))
    Sheets("Applications").Range(unionrng.Address).SpecialCells (xlCellTypeVisible)

答案 1 :(得分:1)

您有几个选项 - 通过逗号连接范围地址或构建单独的范围并使用Union方法。请查看Microsoft帮助中的How to: Refer to Multiple Ranges文章。

答案 2 :(得分:1)

您可以尝试在这样的循环中使用Union。

Dim x As Long
Dim y As Long

For y = 1 To 13
    For x = 1 To r

        If y <> 7 Then
            If RangeCopy Is Nothing Then
            Set RangeCopy = cells(x, y)
            Else
            Set RangeCopy = Application.Union(RangeCopy, cells(x, y))
            End If
        End If

    Next x
Next y
相关问题