+ Reply to Thread
Results 1 to 4 of 4

Run code with out running code

Hybrid View

kwik98 Run code with out running code 01-29-2017, 06:39 PM
Trebor76 Re: Run code with out running... 01-29-2017, 08:37 PM
xlnitwit Re: Run code with out running... 01-30-2017, 04:26 AM
kwik98 Re: Run code with out running... 02-02-2017, 11:34 AM
  1. #1
    Registered User
    Join Date
    04-30-2010
    Location
    Fairmont,WV
    MS-Off Ver
    Excel 2007
    Posts
    66

    Lightbulb Run code with out running code

    Yeah, it's that confusing. I have three workbooks. As workbook1 opens, from the task scheduler, it checks for a date and if its todays date, it runs a code. A later part of that code opens Workbook 2 and paste certain info into it. Heres the problem. I also have code that runs when WB2 is opened. (Workbook_Open) This code is overwriting what the first code is supposed to do in workbook2. Instead of finishing the code out from WB1, it runs the code from the workbook OpenWorkbook function. So, all 3 workbooks do almost the exact same things. I have them opening on a scheduled task. When they open the Open_workbook function runs. I guess what I need is for the open workbook function ( in WB2) to only run when the workbook is opened from the "scheduled task" opening it....not the other workbook code. Same for WB3. I need the OpenWorkbook function to run ONLY when the task scheduler opens it, not the other workbook. Is this even possible?

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,568

    Re: Run code with out running code

    Hi kwik98,

    Is there a cell (or cells) you can rely on that indicates whether the code has been run or not? Have a look at the following example where if cell A1 of Sheet1 has x in it the code (a simple message box) will run, or else it won't:

    Option Explicit
    Private Sub Workbook_Open()
    
        If Sheets("Sheet1").Range("A1") = "x" Then
            MsgBox "This is just a test"
        End If
    
    End Sub
    HTH

    Robert
    Last edited by Trebor76; 01-29-2017 at 08:46 PM.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Run code with out running code

    Hi,

    You might either disable events when opening the workbook in code, or simply replace the workbook_open code with an auto_open routine in a normal module, which won't run automatically if the workbook is opened in code.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Registered User
    Join Date
    04-30-2010
    Location
    Fairmont,WV
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Run code with out running code

    Neither will work for me but thanks for the attention. After banging my head against the wall for several hours I just ended up rearranging half a dozen codes in an order to fire differently. Thanks again

+ 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. Stepping through code produces different result than running code
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2015, 08:27 AM
  2. Replies: 21
    Last Post: 03-04-2015, 07:19 PM
  3. Help in macro code to stop code running for certain time
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-05-2015, 02:35 AM
  4. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  5. [SOLVED] To improve Efficiency of code, code running too long
    By andywsw in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2012, 05:54 PM
  6. Running excel vba code from inside access vba code
    By Lanox in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2011, 09:09 AM
  7. Code the saves filter info to reapply after running other code
    By Wedge120 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2011, 05:49 PM

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