+ Reply to Thread
Results 1 to 5 of 5

When stepping through code using F8, macro automatically runs at Workbooks.Open line

  1. #1
    Registered User
    Join Date
    03-12-2014
    Location
    Newfoundland, Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    When stepping through code using F8, macro automatically runs at Workbooks.Open line

    On my work computer (Excel 2010, Win 7) when I am stepping through my VBA code using F8 and come to a Workbooks.Open line, the macro automatically kicks in and runs through to the end instead of just stepping to the next line of code. This happens nearly every time but occasionally it works as it should. To prevent this, I have to put a breakpoint on the next line following Workbooks.Open and after that I can step (F8) through the rest of the code. I have never had this problem before and it doesn't happen on my home computer. Any ideas?

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,231

    Re: When stepping through code using F8, macro automatically runs at Workbooks.Open line

    Hi exelji and welcome to the forum.

    Try putting a DoEvents before and after the Workbooks.Open line in your code. See if that fixes the problem.
    http://support.microsoft.com/kb/118468
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    03-12-2014
    Location
    Newfoundland, Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: When stepping through code using F8, macro automatically runs at Workbooks.Open line

    Thanks MarvinP. I read the MS article, though I don't fully understand all the technical parts. I tried your suggestion and it's definitely going to save me from a lot of frustraion. But I am now wondering why this would suddenly begin happening to my code? I have been writing VBA for years and don't remember having this issue. Does it have anything to do with Windows 7. I don't recall if this started happening immediately after I got a new work laptop with Windows 7 back in November but I don't have the problem on my WinXP computer at home.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,231

    Re: When stepping through code using F8, macro automatically runs at Workbooks.Open line

    The idea with DoEvents is, the VBA code will wait for other things to happen before trying to do more VBA code.
    For example - if your code calls to open another file and then go to sheet1, which sheet 1 do you want to activate? Sheet1 in the just opened file or Sheet1 in the file with the VBA code in it?

    DoEvents waits for the operating system to complete all those other OS events before trying to perform the next line of VBA code. If timing problems are happening, DoEvents will wait before trying to perform the next line of VBA.

    I hope this solved your problem.

  5. #5
    Registered User
    Join Date
    03-12-2014
    Location
    Newfoundland, Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: When stepping through code using F8, macro automatically runs at Workbooks.Open line

    Follow up on my original post: I added DoEvents before and after my Workbook.Open line as suggested and it seemed to solve my problem. When I stepped through the Workbook.Open line, it stepped to the next line of code. However, today, I am working with another workbook with same issue. I added DoEvents before and after the Workbook.Open line as you suggested and, once again, as I step (pressing F8 in the VBE) through the Workbook.Open line, the macro runs to the end as if I had pressed F5. Is there something else going on here?

    Please Login or Register  to view this content.

+ 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. Vba code to run my macro in all open workbooks
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2014, 04:00 AM
  2. Problem Single-Stepping Through workbooks.open
    By StevenHB in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-11-2012, 10:05 PM
  3. Workbooks automatically open macro
    By longbow007 in forum Excel General
    Replies: 0
    Last Post: 06-16-2010, 08:58 PM
  4. Code should runs once per line
    By Crispie38 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2007, 06:42 AM
  5. macro or code to open multiple workbooks
    By Duane Reynolds in forum Excel General
    Replies: 1
    Last Post: 03-14-2006, 04:25 AM

Tags for this Thread

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