PDA

View Full Version : Macro to unprotect a form to get an address & copy into an envelope & reprotect form



Chukesgirl
08-04-2008, 05:15 PM
I have a template form that is protected. In the form there is a text box control (which is in a table because there can be more than one address) for the user to insert an address. I need the user to be able to create an envelope from that address text box. I would like a macro that will do the folllowing things after the user has put his cursor on the address:
1. unprotect the document
2. select the cell with the address in it and copy it
3. create the envelope
4. add the envelope to the document
5. re-protect the document
6. As a bonus, it would be nice if it would print the whole thing, but not necessary.:help

macropod
08-04-2008, 05:38 PM
Hi Chukesgirl,

You don't need to unprotect the document to retrieve something from a formfield. All you need is something along the lines of:
ActiveDocument.FormFields(“Text1”).Result

Even better, If the form is set up appropriately, with an envelope page, you don't even need a macro to fill in the addressing details on the envelope - all you need is for the formfield properties to be set to 'calculate on exit' and for the envelope to have the relevant cross-references back to the formfields. Easy.

With a little bit more field coding, any blank lines on the envelope arising out of addresses with fewer than the maximum # of lines can be suppressed.

Chukesgirl
08-04-2008, 09:03 PM
Iam not sure how this solution willl work for me because there is more than one place that the address can be taken from, actually, there are 3 address text boxes but the user only adds information to the one that applies to the type of mailing they are doing, so it seems like I would have to put in a lot of If statements for the 3 different formfield properties, depending on which type of mailing the user does? I do like the idea of putting in an envelope page---just not sure how to code this. Thanks.

macropod
08-04-2008, 09:24 PM
Hi Chukesgirl,

Whether you use vba or field coding, you'll still need to test the fields in much the same way. Yes, the field coding will be very different but, hey, there's none of the macro security issues to deal with and, unlike macros, field updates triggered by 'calculate on exit' can't be disbled.

If you want to post a copy/mock up of your document, plus details of what you want to do, I can help with the field coding.

Chukesgirl
08-05-2008, 09:42 AM
Hi Macropod,
I am attaching a copy of the document for your assistance. I changed the macro enabled template to a macro enabled document, for posting purposes. I made comments directly on the document. Thanks for your help.

macropod
08-05-2008, 04:08 PM
Hi Chukesgirl,

Since you're using checkboxes, some code will be required. However, I don't see any code in your attachment - even though it's in docm format.

I've assumed that all three checkboxes can't be set to true at the same time, and have included some code to make sure that's the case.

I've also deleted your unprotected Sections, as they're incompatible with the use of formfields to gather the addresses.

If also edited the formfield peoperties for the checkbox & address formfields, and have added the field coding to generate the envelope page. You'll need to take care of:
. setting the page layout to direct the 2nd page to the envelope feeder; and
. the address formatting, for which users should insert carriage returns between the address lines - otherwise you'll need a separate field for each address line (these could be placed in-line in the body of the document).