|
Often users (and not too long ago myself) ask, "How do I
pass data from a macro to a UserFom or vice versa.?" This Microsoft
Word Help & Tips page
has been reworked extensively after I received a friendly rebuke from one VBA
expert and fellow MVP plus some valuable schooling from him and and several
others.
Bonus Tip:
A primer for a basic UserForm and other helpful tips on UserForms can be found here:
UserForms.
When the page opens, click the "UserForm" tab.
The examples given here aren't a practical solution to a specific task,
but provided to illustrate a few of the various methods available. The methods
illustrate both the calling macro code and UserForm code. A link for
downloading a template containing the macros and UserForms is located at the end of
this tips page.
When you have downloaded and installed the template you can view the
UserForms and calling macro code in the VBA Editor. To access the editor
in Word, press ALT+F11. To ensure you have a similar view (including the
Project Explorer and Properties Window) to match the following screen shots,
after the editor opens press F4 and CTRL+r.
The calling macros use a familar InputBox to allow you to enter a string of
text to pass to the UserForm. The calling macro PassData1 uses a input box
with "default" text. Again in a practical situation, you wouldn't even
need to pass data in this method. It is provide here just to illustrate
how it could be done. |