+ Reply to Thread
Results 1 to 3 of 3

How to stop running "ThisWorkbook" codes when opening Excel file by macro

Hybrid View

  1. #1
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    How to stop running "ThisWorkbook" codes when opening Excel file by macro

    Hi everybody,

    I'd like to ask you for help in this particular case:

    - I have got an Excel file, that runs a macro that opens another workbook and copies over the data from this workbook

    - the problem is that the other workbook runs a macro (launch userform) whenever it's opened, which is annoying for the user.

    Do you have any idea, if one can actually somehow turn off "ThisWorkbook" codes?

    
        Private Sub Workbook_Open()
        Dim Language_Windows As Integer
        Dim Language As Integer
        Dim FCFF_Value
           
            
        'Hodnota Free Cash Flow to the Firm (FCFF)
            FCFF_Value = ActiveWorkbook.Worksheets("3_FCF").Range("I64")
        
        'Show 
            If Application.Max(FCFF_Value) = 0 And Application.Min(FCFF_Value) = 0 Then
            
                'Detect the language of the system
                Language_Windows = Application.International(xlCountrySetting)
        
                'Choose the language version according to the system language
                If Language_Windows = 420 Then
                    Language = 1
                Else
                    Language = 2
                End If
                       
                'Language version that has been chosen by the user already before
                Worksheets("1_Info").Range("Language") = Language
            Else
            
                'Do nothing
            End If
            
        'Opens the first/intial sheet
        ActiveWorkbook.Sheets("1_Info").Select
        
        'The choice of the language version of the userform
            If Worksheets("1_Info").Range("Language") = 1 Then
            
            'Shows Czech version
                UserForm_CZ.Show
            Else
            
            'Shows English version
                UserForm_EN.Show
    
            End If
    End Sub

    Thank you for any suggestion!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: How to stop running "ThisWorkbook" codes when opening Excel file by macro

    Disable events.
    Applicaton.EnableEvents = False
    
    ' open other workbook
    
    Application.EnableEvents = True
    
    ' continue with rest of code
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: How to stop running "ThisWorkbook" codes when opening Excel file by macro

    Thank you! Works great!

+ 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. Running Code After "Opening File" Event Has Triggered Data Connection Refresh
    By david.nicholls in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2013, 07:22 AM
  2. [SOLVED] Stop Users Saving Macro Enabled File as ".xlsx"
    By OzTrekker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2012, 11:33 PM
  3. Macro to select "Continue" when opening another file and prompted to update links
    By kwaldersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2012, 11:57 AM
  4. Replies: 2
    Last Post: 10-15-2005, 10:05 AM
  5. [SOLVED] How to realize "enable macro" by VBA when opening a file with macr
    By FrankJIN in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-16-2005, 12: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