排除活动表

时间:2015-08-02 21:39:54

标签: excel vba excel-vba

我这里有一个宏。因此它获取了工作表名称,但我想排除活动工作表显示。我尝试了i=2,这有效,但我不希望有一个空行。有什么想法吗?

Sub GetNames()

    'Headers
    Range("A1").Value = "File Name "
    Range("B1").Value = "Sheet Name "
    Range("C1").Value = "Column Name"

    For i = 1 To Sheets.Count
        Cells(i + 1, 2) = Sheets(i).Name
        Cells(i + 1, 1) = ActiveWorkbook.Name
    Next i

End Sub

1 个答案:

答案 0 :(得分:3)

Dim intRow As Long: intRow = 2

For i = 1 To Sheets.Count
    If Sheets(i).Name <> ActiveSheet.Name Then
        Cells(intRow, 2) = Sheets(i).Name
        Cells(intRow, 1) = ActiveWorkbook.Name
        intRow = intRow + 1
    End If
Next i