Automatically Run an Excel Macro

Posted on the December 7th, 2008 under Workbook and Worksheet by Poer @ Excel VBA/Macro

Auto run macro excel… Do you want to run an excel macros automatically when the file is open or close?

Microsoft Excel provide us the opportunity to run a macro automatically every time we open or close the excel workbook file, using the event Workbook_Open and Workbook_BeforeClose.

In the Microsoft Visual Basic Editor page, in the ThisWorkbook module, we simply create two new sub procedure called Workbook_Open and Workbook_BeforeClose. In both sub procedure, we call the method that we want to run automatically when the workbook is open or closed.

Private Sub Workbook_Open ()

    Call onFileOpenMacro

End Sub
Private Sub Workbook_BeforeClose (Cancel As Boolean)

    Call onFileCloseMacro

End Sub

In this example, when the workbook is opened, we will automatically run macros called onFileOpenMacro, we also automatically run macros called onFileCloseMacro just before the excel workbook is closed.

Related Entries

External Resources

Tagged with:

6 Responses to 'Automatically Run an Excel Macro'

  1. January 25, 2009 at 5:47 pm
    Seli
  2. January 29, 2009 at 10:43 am
    Poer
  3. May 26, 2009 at 8:03 pm
    Krish
  4. June 8, 2009 at 9:13 am
    Poer
  5. August 27, 2009 at 9:41 pm
    adi
  6. September 10, 2009 at 12:58 pm
    Poer @ Excel VBA/Macro

Leave a Reply




XHTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
SYNTAX HIGHLIGHTER:
Place your VBA code between <pre> tags like this <pre class="brush:vb"> sub vba() ... end sub </pre>.