Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Merge and Macro Button

Status
Not open for further replies.

alip43

Technical User
Apr 3, 2003
14
GB
I have created a template for a school report in Word (2003) which takes names, form, etc from an excel spreadsheet. The template then has form option boxes (excellent, good, etc) and below this comment and target boxes. I have found a macro which when pressed enables me to protect the option boxes whilst leaving the comment boxes free for editing and have created a button on a toolbar for staff to click when they have chosen their class and completed their mail merge.
However the button disappears as soon as the 'Edit Individual Letter' is pressed.
Is there a way that I can make sure that this button stays available for staff after completion of the mail merge operation to enable them to complete their reports.
 




Hi,

You have not adequately described the problem, because you need to post your code, and describe the CONTROL for 'Edit Individual Letter'.

However, this forum is not the correct one for addressing VBA Code (macro) questions.

Please repost in Forum707 and include the VBA Code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi
Sorry I didn't explain myself very well. The 'Edit Individual Letter' is what appears down the right hand side of the screen when you do a mail merge in Word - I haven't written any code (in fact don't know anything really about vb)
 





option boxes: What are they? There are no Option Boxes in Forms Controls. Please use the terms associated directly with any controls you place on the document. How did you place this control on your document?

comment boxes: What are these? Please answer the same questions regarding these, as there are no Comment Boxes in Forms Controls.

I don't know if its possible to use Forms Fields with MailMerge and then EDIT the Forms Fields after th merge. I could get a CheckBox to work, but not a Text field, which it SEEMS that you are trying to use. But I don't know because the way that you refer to these controls, are not the names associated with the controls.
'Edit Individual Letter': What is this?

Is this



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I don't think you can do this. The FormFields are removed when the merge is done.

You can do it with a Find and Replace operation after the merge, but it isn't entirely straightforward. Briefly:

Design your form including all the fields
Save it as an Autotext
Put a placeholder in the merge skeleton
Do the Merge
Insert your Autotext somewhere in a document
Copy it to the clipboard
Do a Find for your placeholder
Replace it with ^c
Hit Replace All
Protect the document for Forms

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 



"Mail Merge and Macro Button"

"I haven't written any code (in fact don't know anything really about vb)"

If there's a Macro Button, there is code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Tony I will give this a go.

Skip - If you create a frame in Word and put in a check box form field - highlight it and click properties - the properties box that appears has the heading 'Check box form field options' - therefore I thought I was using the correct terminology - sorry if this was confusing. The comment boxes are what the teachers will write comments in and are actually Text Form Fields.
As I said in my previous post the macro button was not written by me but found on the net - this button works fine - here is the code for both macros in the document.

Sub MakeCheckBoxesExclusive()
'
' MakeCheckBoxesExclusive Macro
' Macro created 6/11/2008 by
'
Dim oField As FormField

For Each oField In Selection.Frames(1).Range.FormFields
oField.CheckBox.Value = False
Next oField

Selection.FormFields(1).CheckBox.Value = True

End Sub

Sub ProtectNoReset()

Dim pDoc As Dialog
Dim x As Integer
On Error GoTo ProtectNoResetErr

' If the document is protected,
If ActiveDocument.ProtectionType <> wdNoProtection Then

' Unprotect the document.
ActiveDocument.Unprotect

End If

' Display the Protect Dialog box.
Set pDoc = Dialogs(wdDialogToolsProtectDocument)
x = pDoc.Display

' If Cancel was chosen, exit this procedure.
If x = 0 Then Exit Sub

' Protect the document.
ActiveDocument.Protect Password:=pDoc.DocumentPassword, _
NoReset:=True, Type:=2

ProtectNoResetErr: 'NOTE: This line MUST be left aligned.
If Err <> 0 Then MsgBox Err.Description

End Sub

It is the ProtectNoReset which allows the check boxes to be used along with the Text form fields. The check boxes are at the top of the document then there is a continuous break, then the text form fields.
The protectnoreset macro button is placed in one of the toolbars and works fine except when the document is merged - this is when the protectnoreset button previously created disappears - therefore staff cannot fill in the form properly.
 
hi Skip,
If there's a Macro Button, there is code
Not necessarily. Condsider a MACROBUTTON field coded as:
Code:
{MACROBUTTON NoMacro Type something here}
A MACROBUTTON field coded this way can be used to solicit user input instead of firing a macro.

Cheers

[MS MVP - Word]
 




"...works fine except when the document is merged..."

That's what Tony and I have been trying to tell you. This will not work when a MERGE occurs.

In my opinion, it would be much easier to do the entire thing in Excel, but Tony has suggested a method for Word, that does not include FormFields.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip said:
In my opinion, it would be much easier to do the entire thing in Excel
My Excel is rusty these days but how would you do it in Excel? Page layout of variable length text is not one of Excel's strengths.

Skip said:
... but Tony has suggested a method for Word, that does not include FormFields.
It does include FormFields - it just adds them after the Merge. It's a horrible kludge and part of me thinks there ought to be a better way but it's not springing to mind.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi
My form fields are still all there when the merge takes place it is just the button I have created and placed on the toolbar to run the macro which disappears. The merged report document can be used by enabling the forms toolbar and protecting the form then unprotecting it when the comment boxes are filled in - this however would be unusable for the staff to do as they were filling in each report.
 
A toolbar button disappears during a merge operation?

Why do you need to unprotect the Form after filling in a Field?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi Tony
I need this button as it runs the macro before any fields are filled in so that the check boxes are protected but the text boxes aren't. This is so staff do not have to keep protecting and unprotecting the form depending on which part of the form they are filling in.
 
Hi alip43,

I'm not sure we're really communicating here. As far as I understand what you're trying to do, it should't be so complicated, so let's take a few steps back.

[ul][li]You have student details in an Excel worksheet.[/li]
[li]You want to create a number of entities in Word. I use the term 'entities' deliberately as being non-specific.[/li]
[li]Do you create a single document? Or one document per student, or per teacher, or what?[/li]
[li]Do the documents contain a single section? Or one section per student, or per teacher, or what?[/li]
[li]Are you using FormFields (controls from the Forms toolbar)?[/li]
[li]Are you using ActiveX controls (from the Control Toolbox)?[/li]
[li]What are you using Toolbar buttons for? And which one disappears?[/li]
[li]What is in - and isn't in - each merge result in terms of controls?[/li]
[li]What manual operations take place after the merge?[/li]
[li]In particular, what operations take place that need protection off, and why?[/li][/ul]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi Tony
I'm not quite sure what has happened here. I have come back to this after the weekend and it is now working ok. The problem I had was that the form tick boxes needed protection to be filled in but the text fields needed to be unprotected to be filled in. Now when I protect the form all the various 'entities' can be filled in - therefore no need for the extra macro and no need for the extra toolbar (that kept disappearing!).
However, thank you very much for your time and patience with me when trying to explain the problem.
Regards
Alison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top