Propriedade Application.ActiveSheet (Excel)

Retorna um objeto que representa a planilha ativa (a planilha na parte superior) na pasta de trabalho ativa ou na janela ou pasta de trabalho especificada. Retorna Nothing se nenhuma planilha estiver ativa.

Sintaxe

expressão.ActiveSheet

expressão Uma variável que representa um Aplicativo objeto.

Comentários

Se você não especificar um qualificador de objeto, esta propriedade retornará a planilha ativa na pasta de trabalho ativa.

Se uma pasta de trabalho aparecer em mais de uma janela, a propriedade ActiveSheet poderá ser diferente em janelas diferentes.

Exemplo

Este exemplo exibe o nome da planilha ativa.

MsgBox "The name of the active sheet is " & ActiveSheet.Name

Este exemplo cria a visualização de impressão da planilha ativa com o número de página na parte superior da coluna B em cada página.

Sub PrintSheets()

   'Set up your variables.
   Dim iRow As Integer, iRowL As Integer, iPage As Integer
   'Find the last row that contains data.
   iRowL = Cells(Rows.Count, 1).End(xlUp).Row
   
   'Define the print area as the range containing all the data in the first two columns of the current worksheet.
   ActiveSheet.PageSetup.PrintArea = Range("A1:B" & iRowL).Address
   
   'Select all the rows containing data.
   Rows(iRowL).Select
   
   'display the automatic page breaks
   ActiveSheet.DisplayAutomaticPageBreaks = True
   Range("B1").Value = "Page 1"
   
   'After each page break, go to the next cell in column B and write out the page number.
   For iPage = 1 To ActiveSheet.HPageBreaks.Count
      ActiveSheet.HPageBreaks(iPage) _
         .Location.Offset(0, 1).Value = "Page " & iPage + 1
   Next iPage
   
   'Show the print preview, and afterwards remove the page numbers from column B.
   ActiveSheet.PrintPreview
   Columns("B").ClearContents
   Range("A1").Select
End Sub

Suporte e comentários

Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.