PDA

View Full Version : copy vba code when mail merging



markw
06-18-2008, 08:18 PM
Hi
I am a novice when it comes to vba so i would like to say thanks in advance to any replies.
I have created a Word 2003 doc that has a button that brings up a form with list boxes and check boxes.
This document also has merge fields in it.
I was wondering is there a way to get the code to copy to the new mail merge document (only 1 doc generated) so that the button and form still work.
At the moment you need to use the form and enter the information first then do the mail merge. After that the button doesn't work (the code or form isn't copied over).
Any help would be good.
code example would be good too.

Thanks

Oorang
06-19-2008, 02:42 PM
The easiest way to move code, is copy the file that has the code it in and then work with the copied file. If you generate a whole new file, then you have to put the code into the new file and to do that you will need to have your users change their security settings to allow access to the VBE which is not always desirable. If the first option is possible it is preferable. Failing that you might want to consider an Add-in so the code is available across multiple documents. Directly writing code with code should be a last resort. (And depending on how smart you AV is, self modifyng code might set it off.)

markw
06-19-2008, 04:13 PM
Ok, thanks for your help. I will give it a go.