New to VBA and have question
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
Re: New to VBA and have question
Are you wanting to load the UserForm manually?
Re: New to VBA and have question
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
Re: New to VBA and have question
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?
Re: New to VBA and have question
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.
1 Attachment(s)
Re: New to VBA and have question
Heres a sample of how to transfer textbox text to a document.
Also, it starts up the userform upon document open. Enable your macros.
Re: New to VBA and have question
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
Re: New to VBA and have question
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
Re: New to VBA and have question
Easier said than done bro....but I'll give it a shot.
Thanks,
Blake
Re: New to VBA and have question
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
Re: New to VBA and have question
Thanks for your help bro!!!