Suppressing Msgbox during Testing

L

libby

Can't you just put a ' infront of the code you don't want
to be executed, thus making it a comment while you don't
want it to run.
 
T

Tim Childs

Hi

thanks for those ideas...the reservations about these methods are they stop
me being able to see what will happen if I am a user - I think it is risky
to assume things will always work as you expect* that is why I want to turn
the msgbox off just for the multi-sheet test. Commenting out the code is
risky as I may not remember to uncomment it.

Thanks

Tim

* I am often wrong-footed esp. as the complexity of interaction of differnet
parameters increases
 
J

John Wilson

Tim,

If you use the method to manually set a TestMode variable to true
you can easily switch between the two modes.
When working on "live" workbooks I usually use it in the following way:

Sub TestMe()
' code that I know works
End Sub

If I'm trying to modify or enhance the code I do this with that same
module:

Sub TestMe()
If TestMode = False Then
' code that I know works
Else
' modified code that I'm testing
End If
End Sub

Whenever I'm working on the workbook, I can set TestMode to True
and do whatever I want with it. Since I have to manually set it to test,
I never have to worry about the user running into my untested code
and I can test it as a regular user myself.
When I'm happy that everything works well, I just delete the if statements
and my old code.

I do the same for UserForms too.
Place a button on the form to test some code, but set the button
invisible IF TestMode = False.

With the above method, whenever I have to release the workbook for someone
else to use it, I don't have to worry about what I may heve left in there
or was in the middle of when I save and close it.

John
 
T

Tim Childs

John

Many thanks for coming back with this further ost and explanation - I will
try it out in my context

Best wishes

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top