Can you use a form to INSERT an auto macro?

A

Angyl

I've created a locked template form in Word and a UserForm to go with it.
The form has a macro that pops up the UserForm any time you start a new
document from the template.

Problem I have is that when you SAVE what you did off of the template and
later go back to work with it, the userform doesn't pop up. You're free to
edit directly in the form. Is there a way I can make it so that the userform
always comes back up when you open the document saved from the template?
 
G

Greg Maxey

I assume that your code to show the userform in a new document is in a
Auto_New routine.

Put the same code in and Auto_Open routine
 
D

Doug Robbins - Word MVP

Create another macro in the template with the name of Autoopen() that
contains code to call the userform. You may want to include an Initialize
event in the userform to reload the previously entered data into the
controls on the userform to facilitate its use.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Angyl

THANKS GUYS!

One small problem: The user Form comes up empty. The Document has all the
saved data, of course. Is there any way to kinda "reverse" what the user
form normally does and add to the onopen() command to have it populate itself
from the data in the document?
 
G

Greg Maxey

Yes there is. As Doug says you will want to have an Initialize event
that populates your form from date in the document e.g.,

Sub UserForm_Initialize (not sure if that is exact, but it is available
form the VBE pulldown)

Me.Textbox1.Text = ActiveDocument.Bookmarks("Blahblah").Range.Text

End Sub
 
C

Charles Kenyon

Or, you could save the info from your userform as document variables the
first time around and when initializing the form check for the existence of
the variables. Use their contents to populate the form. Use DocVariable
fields in the document to display the data.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
A

Angyl

NICE! But it's not working. The Sub UserForm1_Initialize is fine, I think,
but

With UserForm1

Me.ClientName.Text = ActiveDocument.Bookmarks("ClientName").Range.Text

End Sub


Brings up an error saying "Invalid use of Me keyword"
 
D

Doug Robbins - Word MVP

Hi Greg,

The underscores belong in Excel, not in Word.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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