Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Delete unused form fields
Hi there
I have the following text box form fields set for a report heading: [Test Method] of [Active] in [Product], [Strength] [Dosage] The report heading is centred. When all the fields are entered the heading centers correctly on the page, however, if I do not have data for the [Strength] or [Dosage] fields, because the field markers remain in the heading, the heading becomes off-centre, even though the fields do not print. How can I correct this? Thanks, Silena |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Delete unused form fields
I take it that these are text form fields in a protected form? Inevitably
the fields and the spacing between them will occupy a particular amount of space that will be reflected in their alignment as long as they are present. The best answer is not to use the form fields for this purpose. Ideally I would suggest a Userform to collect the data and write it into the heading then, if necessary, protect the form - For the basics, see Word MVP FAQ - Userforms http://word.mvps.org/FAQs/Userforms.htm for a more in depth explanation, see http://gregmaxey.mvps.org/Create_and...a_UserForm.htm However, it could also be done less elegantly with a macro run on exit from the Product field to question whether the extra heading parts are required and to add them if necessary, thus maintaining the alignment. The following macro is run on exit from the 'Product' form field, and assumes that the field is Text3. Everything else from the line should be removed. On exit from the Product field, the macro prompts for content for the two now removed fields and depending what is entered adds the result to the end of the heading line. The macro is then removed from the field and the next form field is selected. If you require the information from what was a field and is now text to be reproduced elsewhere in the document, you can add the code to the macro to apply the results of the two input boxes wherever you require it. http://www.gmayor.com/installing_macro.htm Sub AddStrengthAndDosage() Dim sStr As String Dim sDos As String Dim sRes As String Dim oRng As Range Dim bProtected As Boolean Dim fCount As Long sStr = InputBox("Enter strength if relevant", "Heading") sDos = InputBox("Enter dosage if relevant", "Heading") If Len(sStr) + Len(sDos) 0 Then 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.TypeText ", " If sStr "" Then Selection.TypeText sStr If sDos "" And sStr "" Then Selection.TypeText " " End If Selection.TypeText sDos 'Note Text3 here represents the field from which the macro 'is run i.e. the 'Product' field. Change the Text3 'to reflect the true name of the field (in three places) sRes = ActiveDocument.FormFields("Text3").Result ActiveDocument.FormFields("Text3").Select With Dialogs(wdDialogFormFieldOptions) .Exit = "" 'and remove the exit macro .Execute 'apply the changes 'but note that this clears the value from the cell End With 'So restore the value ActiveDocument.FormFields("Text3").Result = sRes 'Reprotect the document. If bProtected = True Then ActiveDocument.Protect _ Type:=wdAllowOnlyFormFields, _ NoReset:=True, _ Password:="" End If End If End Sub Silena K-K wrote: Hi there I have the following text box form fields set for a report heading: [Test Method] of [Active] in [Product], [Strength] [Dosage] The report heading is centred. When all the fields are entered the heading centers correctly on the page, however, if I do not have data for the [Strength] or [Dosage] fields, because the field markers remain in the heading, the heading becomes off-centre, even though the fields do not print. How can I correct this? Thanks, Silena |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to delete unused styles - Macro? | Microsoft Word Help | |||
Printing UNUSED fields in forms | Microsoft Word Help | |||
How do I delete unused Heading formats from drop down menue | Microsoft Word Help | |||
Word should let me automatically delete all unused styles. | Microsoft Word Help | |||
Delete unused columns on spreadsheet | Microsoft Word Help |