[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

Stepping through like F5

Hi guys,

I have some code below, i like to step through bit by bit to test.

When i press F8 on the below code, it is running striaght through it, how/why is this?! I am not using F5, its F8....

Any help would be appreciated!

Thanks
0
Seamus2626
Asked:
Seamus2626
2 Solutions
 
Martin LissRetired ProgrammerCommented:
You need to first set a breakpoint someplace, press f5 and then f8 when it gets to the breakpoint.

Here's an article of mine on debugging. Don't worry that it says VB6 since most of it applies to VBA.

http://www.experts-exchange.com/A_8631.html
0
 
Seamus2626Author Commented:
But i shouidnt need to set a breakpoint, if that wasnt opening a file, i could step through code w/o setting a breakpoint.....
0
 
Martin LissRetired ProgrammerCommented:
You didn't actually show the code so why don't you do that now.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Seamus2626Author Commented:
Sorry Martin

Sub DoingTheWork()

Workbooks.Open Filename:= _
        "A:\Horis Info\ME_denniss_Project\whynee Downloads\CurrentMonth.xlsx"


Sheets("Incountry").Select


       
    Cells.Select
    With Selection
        .WrapText = False
        .MergeCells = False
    End With
0
 
Martin LissRetired ProgrammerCommented:
OK I don't see anything unusual so why don't you try putting a breakpoint at the Workbooks.Open line.
0
 
Martin LissRetired ProgrammerCommented:
Or just put your cursor somewhere in the sub and press F8.
0
 
Seamus2626Author Commented:
I can work around it by putting the breakpoint in at sheets, but i want to know its runnning through the code without my permission!!
0
 
Martin LissRetired ProgrammerCommented:
Sorry but I'm not sure what you mean. Can you list, step by step, what you are doing and what you expect to happen?
0
 
Seamus2626Author Commented:
So, i expect to go into the sub and press F8, then i expect the cursor to move through the first line of code, then when i press F8 again, i expect it to move through the next, and so on, i dont want it to run through the entire script as if i was pressing F5

Thanks
0
 
Martin LissRetired ProgrammerCommented:
I guess I don't know why it's doing that. Do you perhaps have f8 assigned to something else? What happens if you press the "Step into" menu item?
0
 
NorieCommented:
Exactly what part of the code is this happening on?

Also, how is the code being run/triggered?
0
 
Seamus2626Author Commented:
So, F8 works fine for stepping through all my code, its just when i have the code

Workbooks.Open Filename:= _
        "A:\Horis Info\ME_denniss_Project\whynee Downloads\CurrentMonth.xlsx"



Thats the problem, when im opening a file, it triggers the code off to run through the rest off the sub

If my sub was

Sub test

Msgbox "hello"
Msbox "hello"
[A1].slect

End sub

F8 would step through each line perfectly
0
 
Martin LissRetired ProgrammerCommented:
Probably because the other workbook becomes active.
0
 
Harry LeeCommented:
Seamus2626,

Excel has be behaving the way you experienced for many many years.

If there is a Workbooks.Open in the code, F8 or Ctrl-F8 would work before it but once you pass the Workbooks.Open, the VBA will just run all the way to the end.

The only way to workaround it is to put a Break Point right after the Workbooks.Open, so that you can continue to use F8 or Ctrl-F8 to debug your code.

As far as I know Excel behaves this way since Excel 2000.
0
 
Seamus2626Author Commented:
Thanks for the info guys!
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now