I want to create a form in Word but I only want specific lines to print on
each day of the week.
For Example
On Sunday I want to print lines 1 - 5 , 10,12,16,20-40
On Monday I want to print lines 1 - 5, 11,13,17,20-40
On Wednesday I want to print lines 1 - 5, 14, 18, 20-40
etc...
I can create multiple documents but I am trying to keep this information in
one document for ease of updating.
This can be done.
Start by defining seven paragraph styles in the form template, naming them with
the days of the week. They can all be based on Normal style (or on Body Text
style) with identical formatting; only the seven different names are important.
In the body of the template, apply each style to every line that should appear
only on that day; in your example, the style named Monday would be applied to
lines 10, 12, and 16, while lines 1-5 and 20-40 should stay in Normal style so
they appear on every day.
You can make a choice at this point: If the form is a protected form with form
fields, you can put a dropdown form field somewhere in the form and put the
seven day names into it as the choices. If it isn't already a protected form,
there's no need to make it one; instead you can create a custom dialog (a
"userform") to pop up and let you select the day. Finally, if you'll always be
printing the form for the current day (that is, you never want to print a form
for tomorrow or some other day of the week), you can just program the macro to
automatically use the current day's name.
Now you need a macro that changes the Hidden attribute to True for each style
except the one for the chosen day, prints the document, and then restores all
the styles to visibility. Name the macro FilePrint so it will run instead of the
built-in Print command. Here's the code for a protected form containing a
dropdown named fldDay:
Sub FilePrint()
Dim currDay As String
currDay = ActiveDocument.FormFields("fldDay").Result
ChangeStyles currDay
Application.ScreenRefresh
Dialogs(wdDialogFilePrint).Show
UnChangeStyles
End Sub
Private Sub ChangeStyles(StyleName As String)
' Hide all the day styles, then unhide one
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
.Styles("Monday").Font.Hidden = True
.Styles("Tuesday").Font.Hidden = True
.Styles("Wednesday").Font.Hidden = True
.Styles("Thursday").Font.Hidden = True
.Styles("Friday").Font.Hidden = True
.Styles(StyleName).Font.Hidden = False
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub
Private Sub UnChangeStyles()
' Hide all the day styles, then unhide one
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
.Styles("Monday").Font.Hidden = False
.Styles("Tuesday").Font.Hidden = False
.Styles("Wednesday").Font.Hidden = False
.Styles("Thursday").Font.Hidden = False
.Styles("Friday").Font.Hidden = False
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub