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
Seamus2626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
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 LissOlder than dirtCommented:
You didn't actually show the code so why don't you do that now.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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 LissOlder than dirtCommented:
OK I don't see anything unusual so why don't you try putting a breakpoint at the Workbooks.Open line.
0
Martin LissOlder than dirtCommented:
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 LissOlder than dirtCommented:
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 LissOlder than dirtCommented:
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
NorieVBA ExpertCommented:
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 LissOlder than dirtCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seamus2626Author Commented:
Thanks for the info guys!
0
Martin LissOlder than dirtCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.