Single or Multiple Variables to Populate Message Boxes in Different Subs

AnyOldName

New Member
Joined
May 18, 2019
Messages
8
I normally use a string variable (Var_MsgText) as an input to message boxes but I'm currently writing my biggest piece of code to date that has multiple subs that all use message boxes. I don't want Var_MsgText to be a public sub as that would risk incorrect carry over of the content between different subs so the two approaches I'm considering are:

Approach 1: Var_MsgText1 in one sub, Var_MsgText2 in the next sub etc, that this means creating more variables but maybe I'm worrying about nothing

Approach 2: Have a single variable name (Var_MsgText) that's used in multiple subs but re-declaring it at the beginning of each sub so that its empty, is that possible or will it cause problems?

Approach 3: Someone gives me a better idea than 1 or 2

Thanks in advance.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I'm not an expert, by any means - and stand to be corrected (or shot down in flames) by some very clever Folk who help on this great site.
That having been said, for my two pennies worth:

1. Personally, as long as you're not needing the variable (presumably a string?) to service several of your msg boxes at the same time, I'd declare it publicly at the top of a module - with the workbook_open event. It's done then - once and for all, and after all, it's only an instruction to the computer, to hold a tiny bit of memory free for your code to use, so there's no need to re-declare it, or clear it out each time - just use it, as you would any variable; each time you refer to it, the previous data's cleared out, and the new string inserted. No need to declare it any more in any of your code, so it keeps things slightly more curt, too.

2. One other thing - personally, I've stopped using message boxes unless absolutely necessary. I find that it quickly gets tedious for you (or even more so for your users) to have message boxes popping up all the time, and having to react to them. I tend to use UserForms more now days - often small ones which are permanently displayed (by setting the "modeless" property) and having label controls on them. It's just as easy to then use the "Caption" property to pass messages to your users, and whilst it's not quite as "attention-getting" I find it a tidier and more user-friendly way to communicate.

HTH
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top