Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

excel 2010 VBA throws "can't execute code in break mode" while stepping

I have just moved to excel 2010, have discovered surprising behaviour when stepping through code. When stepping through code it often throws the error Can't execute code in break mode.

An example VBA script follows:

Sub nm()

    Sheets("Winput").Select
    Range("A10").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    ActiveSheet.Previous.Select

end Sub

The error are not thrown on Sheets("Winput").Select or Selection.Copy, but are thrown on all other lines. The code runs fine when i trigger the macro.

thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While this may not exactly answer the Can't execute... error, can you please try if the following code throws the same error? I believe that the Select usage in your code is causing this as I've experienced much the same in the past...

Sub nmMod()
    Set Start = Sheets("Winput").Range("A10")
    EndCol = Start.End(xlToRight).Column
    EndRow = Start.End(xlDown).Row
    Start.Resize(EndRow, EndCol).Copy
    Sheet2.Range("A1").PasteSpecial xlPasteAll 'mock action, change as necessary
End Sub

It is best to avoid any kind of selection as much as possible. Emulating a Select action is much slower and gives rise to other issues (ie. They can cancel a standing copy, mess up actions especially involving shapes, etc). It will not be much of a surprise if this is the one causing the error itself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...