Excel VBA Objects: Events and Event Procedures

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ม.ค. 2025

ความคิดเห็น • 5

  • @mixtape8476
    @mixtape8476 ปีที่แล้ว +1

    Thanks mate, it will help me a lot

  • @ExcelMadeEasy444
    @ExcelMadeEasy444 2 ปีที่แล้ว +1

    Nice Explained.

  • @ricardoricric
    @ricardoricric 2 ปีที่แล้ว

    Hi! Do you have any examples regarding workbook sheet change events?

    • @ExcelMacroMania
      @ExcelMacroMania  2 ปีที่แล้ว +1

      Any worksheet event that you want to extend to all sheets in the workbook should go into a workbook-level sheet event. For example, if you use a Change or SelectionChange event in a worksheet, and you want to have the same functionality in all worksheets, you would rather have just one event procedure (SheetChage or SheetSelectionChange) in ThisWorkbook. That applies to any other sheet event and is good practice. Another thing I often do is using the NewSheet event to add a link to a list of contents (if you have that) when a new sheet is created. I also used that event to format every new sheet, for example, the code below copies the headers and format of a reference sheet to every new sheet:
      Private Sub Workbook_NewSheet(ByVal Sh As Object)
      'copy headers from reference sheet to new sheet
      Sheets(1).Rows(1).Copy
      Sh.Paste
      'copy format to new sheet
      Sheets(1).Cells.Copy
      Sh.Cells.PasteSpecial (xlFormats)
      End Sub

    • @ricardoricric
      @ricardoricric 2 ปีที่แล้ว

      @@ExcelMacroMania Thanks for clarifying that! Excelent! :)