PDA

View Full Version : Breakpoint won't clear



LisaLynne
05-15-2008, 06:39 AM
I wrote a VBA macro for a client using MS Word 2003. It has been running successfully for several years, with minor modifications when their data changed.

Recently, it has been stopping at a breakpoint - none are set. The break occurs in the same line of code every time, and ONLY after the machine has been rebooted - on the first execution of the macro. After that, it doesn't occur again until the machine is booted again.

How can I prevent this breakpoint from happening?

Thanks in advance.

Oorang
05-15-2008, 08:40 AM
That sounds like it starting to get corrupted. I would export all of your code modules, create a new document, and import the code into the new document.

Crooz
05-16-2008, 03:30 AM
Be warned, however. Exporting and then importing the corrupted modules is doing just that - re-instating the ("background") corruption.
An idea, that has worked for me several times, is to copy and paste the contents of the module into a new document. Rename the modules as in the original - if necessary. If a userform is used, take down the dimensions of the userform and duplicate (size wise) the userform in the new document. Copy all the command controls from the old userform to the new userform.
If the document itself is full of text, copy and paste this text in the new document -but do not include the last paragraph mark(s). This also applies to any page breaks in the Word document - don't copy them.
Practically all of the information pertaining to a document will be stored (and hidden) by Word in the background under these paragraph marks and page breaks.
Hope this works for you.

Oorang
05-16-2008, 06:23 AM
Be warned, however. Exporting and then importing the corrupted modules is doing just that - re-instating the ("background") corruption.

That is a common misconception. When you export a code module a plain-text file of your source code is created with the .bas/.cls extention. While it is hypothetically (altough unlikely) possible for that plain-text file to be corrupted, any such corruption would be visible to the naked eye in notepad (as the "wrong" bytes would cause notepad to translate them into other characters).
Corruption is almost always at the P-Code level. The VBE generates P-Code as new code is added/remove/changed only for the segment altered. But it doesn't always get all the add/delete/changes blended in quite right. And that is when the problems start. By exporting your modules and then importing the module again the P-Code is created from scratch in the new document. The is nearly always sufficient to deal with a corruption issue.

Crooz
05-16-2008, 06:46 PM
It may not be "hypothetically" possible, but the reason that it IS hypothetical possible is enough to make ALL the changes I suggested... just to be sure. You are probably correct in your assumption that it is a common misconception. And nearly most corrupted documents can be restored to their original origin following your instructions.
In a couple of instances in my case, exporting and importing modules/userforms from the old to the new DID NOT solve the problem - until I started copying and pasting the modules as mentioned in my post. Surprisingly, it also reduces the size of the complete file by at least 20%. Why is that? I don't know myself.
I stand by my submission to LisaLynne and also respect your time and effort for your input. It is a procedure I will practice before going through the whole routine as I discribed in my first post.
Thanx Oorang... and hopefully LisaLynne can get something out of this too.
Check the following MVP website for more information on document corruption: word.mvp.org - search for Word corruption.

gwkenny
05-16-2008, 11:22 PM
My vote (which doesn't count for much) is not possible. I've logged days/weeks/years troubleshooting in production groups that churn out presentations 24/7.

If your file is still corrupted, then it's not with regards to the modules being exported, erased, and re-imported. It has to deal with something else in the document/project. Most likely a section break, but it could even be something innocuous as a paragraph mark.

My experience with 2007 is limited though and that should be noted.

LisaLynne
05-17-2008, 05:30 AM
Thanks, All - I am visiting my client next week & will try these solutions out. I will let you know the results!

Crooz
05-17-2008, 04:12 PM
I tend to lean towards gwkenny account, and partly to Oorangs account. The corruption probably has more to do with the document itself rather than the code that supports it - as Oorang suggested. As I stated in my first suggestion, that this worked for me, I haven't worked out why this happened... only know that it did. That still bothers me because I'm always curious what Word has in store for me the next time I run into "weird" siituations. It keeps me off the streets!
LisaLynne, let us know if our solutions helped.