Auto run macros in Excel / VBA

2

I made several attempts to execute a macro when starting Excel as indicated in the searches I did, although these indications are very simple, in my case they did not work.

I followed the following script:

  • Double click on "This_work_folder" in the VBA Project in "Microsoft Excel Objects"

  • I've filled the code as below:

  • Public Sub Auto_Open()
    
        MsgBox ("Ok")
    
    End Sub
    
  • I ran the generated macro for testing and it worked.

  • I saved the "macro-enabled" worksheet

  • I closed the worksheet and called it, the worksheet is opened but the macro is not executed.

  • To test, I left a syntax error in the code, saved it, closed it and called it again, and neither the error was displayed (when executing the macro the error is presented manually), ie the boot macro is being ignored syntax checking, just because it is not running).

    I changed some of the Excel settings, such as macro enable, for example, but they did not work.

    Before I was testing the call of a function by Call, calling another macro or having a form opened, and it did not work either.

    What is missing or what is wrong with this case?

        
    asked by anonymous 02.04.2016 / 17:48

    1 answer

    2

    I found the problem, the correct code is:

     Sub Workbook_Open()
    
     MsgBox ("Ok")
    
     End Sub
    

    In the examples several names were given with the "Open" event, in my case it only worked with "Workbook_Open". You can use Private Sub or Public Sub, or even Function (I read that function can be used, but I have not tested it).

        
    02.04.2016 / 23:28