+ Reply to Thread
Results 1 to 9 of 9

Private Sub Workbook_Open() Vs Public Sub Auto_Open()

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Hi,

    Can anyone explain the differences between both command? Which is better ? I found it have the same function

    I have used Schedule tasks to open workbook and Auto_Open() running as usual.
    Last edited by Faridwahidi; 11-12-2014 at 10:20 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Hi, Farid,

    AFRAIR Auto_Open is from "old times" while Workbook_Open was introduced with Excel97 and should be used from then on due to the changes in the event section of the VBA-code. Workbook_Open is called prior to Auto_Open. IŽd recommend to use Workbook_Open in ThisWorkbook and just remember Auto_Open in a standard module but not use that command any more (maybe MS decides one day to stop the support of that function although I pretty much doubt that with all the other functions still being supported).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Hi Holger,

    Many thanks for clarification

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    The main difference, besides the location of the code, is that when you open a workbook in code, the Auto_Open won't automatically run - you have to call it explicitly - whereas Workbook_Open will run unless you disable events.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    [.... incorrect comment deleted ....]
    Last edited by joeu2004; 11-12-2014 at 06:43 PM. Reason: incorrect

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Please review what I wrote - emphasis added below:
    Quote Originally Posted by romperstomper View Post
    when you open a workbook in code, the Auto_Open won't automatically run

  7. #7
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Quote Originally Posted by romperstomper View Post
    Please review what I wrote - emphasis added below:
    Quote Originally Posted by romperstomper View Post
    you open a workbook in code, the Auto_Open won't automatically run
    That you did! And it is indeed correct. My bad! I removed my incorrect comment.

  8. #8
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Hi Rory,

    Thanks.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Private Sub Workbook_Open() Vs Public Sub Auto_Open()

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Private sub workbook_open code running workbook_open code from other project
    By marshall_massive in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2013, 06:07 PM
  2. Some Application.OnKey lines not working with Workbook_Open or Auto_Open
    By fonthiller in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2012, 11:55 AM
  3. [SOLVED] Auto_Open Workbook_Open
    By Chip Pearson in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-02-2005, 06:20 PM
  4. Auto_Open Workbook_Open
    By yngve.angelskaar@fusi.no in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2005, 06:17 PM
  5. Auto_Open/Workbook_Open subroutines showing SCREENUPDATING
    By WhytheQ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1