PDA

Click to See Complete Forum and Search --> : New to VBA and have question


blakemckenna
May 10th, 2005, 10:46 AM
I am trying to automate a Word document. I wish to build a form using VBA and when opening the document, I wish the form to be displayed where I can enter values...close the form...and populate the Word document with the entered values.

Can someone start me out on the right track as to what commands and events need to be used?

Thanks,

Blake

RobDog888
May 10th, 2005, 11:32 AM
Are you wanting to load the UserForm manually?

blakemckenna
May 10th, 2005, 11:39 AM
Rob,

I guess I want the form to load when the document is opened and then have an command button that would allow me to close/hide the form.

Blake

RobDog888
May 10th, 2005, 11:43 AM
You can add a UserForm to your document in the VBA IDE. Click Insert > UserForm. Then build it as you would VB6 form.
Are you needing to populate the form from a db or something?

blakemckenna
May 10th, 2005, 12:17 PM
Rob,

I have actually done this process where I inserted a UserForm, however, I'm just not sure how to associate it with the Word Document.

RobDog888
May 10th, 2005, 12:29 PM
Heres a sample of how to transfer textbox text to a document.
Also, it starts up the userform upon document open. Enable your macros.

blakemckenna
May 10th, 2005, 12:38 PM
Rob,

That was a big help, however, one more question regarding predefined fields on the Word Document. How do place a form value into a predefined field already on the document?

Thanks,

Blake

RobDog888
May 10th, 2005, 12:47 PM
You can create a bookmark in the place where you want to insert the data. Then refer to the BM's .Range.Text = Userform.Textbox1.Text, etc.

You can also use the .Find method and replace the found text with textbox contents. :D

blakemckenna
May 10th, 2005, 12:50 PM
Easier said than done bro....but I'll give it a shot.

Thanks,

Blake

RobDog888
May 10th, 2005, 12:56 PM
True, but there is already code in this forum to do it, so it will only take a few searches. ;)
I remember assisting in a thread on .Find

blakemckenna
May 10th, 2005, 01:01 PM
Thanks for your help bro!!!