• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Is there a way to stop ‘Private Sub Workbook_Open()’ macro

ThrottleWorks

Excel Ninja
Hi,

I have written a macro. This macro used another excel file as one of the input file.
For example say Input_1. This file has ‘Private Sub Workbook_Open()’ macro.

So as soon as my macro opens Input_1 file. This macro gets triggered.

This input files gets changed every day hence I can remove / edit ‘Private Sub Workbook_Open()’ part manually.

How do I stop triggering ‘Private Sub Workbook_Open()’ macro if Input file is opened by my macro.

Is there a way to do it. Can anyone please help me in this.
 
Hi @Marc L sir, thanks for the help. I am sorry, I did not understand.

Please consider below example. I have below code in file.
Whenever I open this workbook, this code will trigger.
Even if I open this file manually or by a macro written in another file, below code will trigger.

My doubt is, if I am opening this file with a macro (written in another file), below code should not be triggered. Is this possible.

Code:
Private Sub Workbook_Open()
    If Application.UserName <> "KTM 125" Then
        MsgBox "Welcome " & Application.UserName & " !"
    End If
  
    Worksheets("Macro").Select
    Range("A1").Select
End Sub
 

Cut the event code from worksheet module
and paste it to a standard module
and rename the procedure as Auto_ Open (without space) …​
 
Just disable events temporarily in the calling macro:

Code:
Application.Enableevents = False
Set wb = Workbooks.Open(...)
Application.Enableevents = True
 
Back
Top