Adding Items to a UserForm via VBA

L

LA Lawyer

In Word 2007, I want to be able to change another macro by using ".additem"
to a control on that form using VBA. This addition will be permanent.

How do I use VBA to change another macro?
 
J

Jay Freedman

LA said:
In Word 2007, I want to be able to change another macro by using
".additem" to a control on that form using VBA. This addition will
be permanent.
How do I use VBA to change another macro?

With difficulty. The reason is at least partly to prevent malicious code
from altering other macros to make them malicious.

Before you get involved in that exercise, I'd recommend redesigning the
userform to be "data-driven". Use some data structure (probably a member of
the template's .Variables collection) to store the information about the
items. In the userform's Initialize procedure, read the data and use it to
fill in the control. Elsewhere in the userform code, update the data when
necessary and save the template.

If you can be more specific about what the "item" looks like, which control
the user uses to input the data, and which control will display the date,
then I can show some sample code.

If you really want to pursue the ill-advised course of code modifying code,
you'll need (a) to go to Tools > References in the VBA editor and check
"Microsoft Visual Basic for Applications Extensibility", (b) go to Office
button > Word Options > Trust Center > Trust Center Settings > Macro
Settings and check the option "Trust access to the VBA project object model,
and (c) study the topics in the VBA help about "VBProject Object",
"CodeModule Object", and "InsertLines Method."

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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