Results 1 to 12 of 12

Thread: Bypass Workbook_Open

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    3

    Bypass Workbook_Open

    I am opening a workbook via VBA that has the Workbook_Open event in it. How do you bypass the Workbook_Open Even in code.

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Bypass Workbook_Open

    I'm not sure you can.. you can open a workbook that has a module with Auto_Open in it.. but it will run the Workbook_Open code regardless..

    There is no parameter to prevent this.. If it is your own workbook then I suggest you change it to Auto_Open in a module instead..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Bypass Workbook_Open

    Sopunds like you are opening this workbook from within another workbooks vba code. So not too much you can do. If its in your primary workbook you can do this.
    VB Code:
    1. Private Sub Workbook_Open()
    2.     'Bypass
    3.     Exit Sub
    4.     'Other open code
    5.     'Blah, blah, blah
    6. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Bypass Workbook_Open

    Not meaning to re-start the fight but the Auto_open procedure inside a module will not run unless you specify to run it..

    for example

    VB Code:
    1. Sub WorkBook_Open()
    2.   Msgbox "Workbook open event performed."
    3. End Sub
    4.  
    5. 'in a module (Not ThisWorkbook or behind any sheets)
    6.  
    7. Sub Auto_Open()
    8.   Msgbox "Auto open procedure performed."
    9. End Sub

    Save that into a workbook and then from a second workbook simply do

    VB Code:
    1. Workbooks.Open("C:\MyWorkbook.xls")

    And see which msgbox appears.. you should only get the workbook event.. if however you follow your workbook open code with the following

    VB Code:
    1. ActiveWorkbook.RunAutoMacros xlAutoOpen

    Then you should see both messages..

    The Auto_Open method does not fire unless coded specifically, whereas the Workbook_Open will fire regardless.. (Unless of course you have the security set to high)
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Bypass Workbook_Open

    Right, but if the second workbook can not be modified then that workbooks Open event will fire.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Bypass Workbook_Open

    Correct and if it is locked then there is nothing you can do to change it, apart from set the security higher..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Bypass Workbook_Open

    Instead of going through all this, what is the reason you need to bypass the open event for it? Maybe there is another way to look at this?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    3

    Re: Bypass Workbook_Open

    I need to bypass Workbook_open Event because what I am doing is I have an Excel workbook that in code opens up other Excel files and parses the data. One of the files has the Workbook_open Event to add a command bar that references an Addin I don't have access to. So my Automation fails.

  9. #9
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Bypass Workbook_Open

    Is the file locked down or can you access the VBA behind it.. If so change it to the Auto_Open in a module instead.. It will still fire when the workbook is opened normally
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Bypass Workbook_Open

    If that was the case wouldnt that have been done before a thread was posted?

    How about copying the file, making it writeable, change the vba code and be done with it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    3

    Re: Bypass Workbook_Open

    Everyday I receive numerious Excel Files with different data everyday from different sources. The source that sends the file will not remove the code or module. I am trying to complety automating parsing the data. Setting the security to High actually doesn't work in this instance.

  12. #12
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Bypass Workbook_Open

    Setting the security to high will probably prevent your code from working..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

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



Click Here to Expand Forum to Full Width