Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Waitsu Waitsu is offline
external usenet poster
 
Posts: 5
Default Can I print selected lines using a Macro in Word

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.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Can I print selected lines using a Macro in Word

On Mon, 27 Apr 2009 18:02:03 -0700, Waitsu
wrote:

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Gordon Bentley-Mix on news.microsoft.com Gordon Bentley-Mix on news.microsoft.com is offline
external usenet poster
 
Posts: 126
Default Can I print selected lines using a Macro in Word

It can probably be done, but it would depend a lot on how your document is
configured and your programming skills.

One approach would be to wrap bookmarks around each of the "variable"
sections and then write code to hide/show the various sections according to
the current day of the week. Then you could simply print the document making
sure not to print hidden content.

The macro could be written to automatically hide/show the variable content
automatically when the document is opened, or it could be invoked through a
toolbar button or keyboard shortcut.

If you would like to pursue this course, I suggest that you at least attempt
to create the macro on your own and then post a follow up to the Word
Programming newsgroup if you run into any problems.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!


"Waitsu" wrote:

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.

  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Waitsu Waitsu is offline
external usenet poster
 
Posts: 5
Default Can I print selected lines using a Macro in Word

Thanks - I will try this and see if I can make it work.

"Jay Freedman" wrote:

On Mon, 27 Apr 2009 18:02:03 -0700, Waitsu
wrote:

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Waitsu Waitsu is offline
external usenet poster
 
Posts: 5
Default Can I print selected lines using a Macro in Word

Thanks - My Word skills are fairly good but have not done too much with
macros. i am alweays looking for a challenge so I will give both suggestions
a try and see if I can make it work.


"Gordon Bentley-Mix on news.microsoft.com" wrote:

It can probably be done, but it would depend a lot on how your document is
configured and your programming skills.

One approach would be to wrap bookmarks around each of the "variable"
sections and then write code to hide/show the various sections according to
the current day of the week. Then you could simply print the document making
sure not to print hidden content.

The macro could be written to automatically hide/show the variable content
automatically when the document is opened, or it could be invoked through a
toolbar button or keyboard shortcut.

If you would like to pursue this course, I suggest that you at least attempt
to create the macro on your own and then post a follow up to the Word
Programming newsgroup if you run into any problems.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!


"Waitsu" wrote:

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.



  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Waitsu Waitsu is offline
external usenet poster
 
Posts: 5
Default Can I print selected lines using a Macro in Word

OK - I am able to hide the lines that I do not want to see manually, i have
not worked on the macro yet.

My next issue is that the text is in a table, when I hide the items I do not
want to see, I get a blank box - is there any way to hide the table row that
is empty or am I out of luck on that?

Thanks

"Jay Freedman" wrote:

On Mon, 27 Apr 2009 18:02:03 -0700, Waitsu
wrote:

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Can I print selected lines using a Macro in Word

If you select the entire row, including the row marker in the right margin
(which is visible if you display nonprinting characters with the ¶ button), and
then apply the paragraph style to that, then the table row will hide when you
set the style's Hidden attribute to True. If you select any less than the entire
row before applying the style, then the row won't hide.

On Wed, 29 Apr 2009 18:10:06 -0700, Waitsu
wrote:

OK - I am able to hide the lines that I do not want to see manually, i have
not worked on the macro yet.

My next issue is that the text is in a table, when I hide the items I do not
want to see, I get a blank box - is there any way to hide the table row that
is empty or am I out of luck on that?

Thanks

"Jay Freedman" wrote:

On Mon, 27 Apr 2009 18:02:03 -0700, Waitsu
wrote:

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Waitsu Waitsu is offline
external usenet poster
 
Posts: 5
Default Can I print selected lines using a Macro in Word

Thanks - that does hide the row.

The next issue that I am having is that when I hide any text it adds
multiple blank pages in the document. When I unhide the font the blank pages
dissappear.

Here is the piece of code that is hiding the text:

If MyStr = "Sunday" Then
.Styles("Sunday").Font.Hidden = False
.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("Saturday").Font.Hidden = True
.Styles("Not Sunday").Font.Hidden = True
.Styles("Normal").Font.Hidden = False

I am doing this because there are a couple of days that I need items hidden
that I need to see every other day of the week.

Thanks

"Jay Freedman" wrote:

If you select the entire row, including the row marker in the right margin
(which is visible if you display nonprinting characters with the ¶ button), and
then apply the paragraph style to that, then the table row will hide when you
set the style's Hidden attribute to True. If you select any less than the entire
row before applying the style, then the row won't hide.

On Wed, 29 Apr 2009 18:10:06 -0700, Waitsu
wrote:

OK - I am able to hide the lines that I do not want to see manually, i have
not worked on the macro yet.

My next issue is that the text is in a table, when I hide the items I do not
want to see, I get a blank box - is there any way to hide the table row that
is empty or am I out of luck on that?

Thanks

"Jay Freedman" wrote:

On Mon, 27 Apr 2009 18:02:03 -0700, Waitsu
wrote:

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.


  #9   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Can I print selected lines using a Macro in Word

I can't think of any reason that _hiding_ anything should cause new blank
pages to appear. Something is seriously wrong here. If you email a copy of
the template to me, I'll try to figure out what's happening.

Waitsu wrote:
Thanks - that does hide the row.

The next issue that I am having is that when I hide any text it adds
multiple blank pages in the document. When I unhide the font the
blank pages dissappear.

Here is the piece of code that is hiding the text:

If MyStr = "Sunday" Then
.Styles("Sunday").Font.Hidden = False
.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("Saturday").Font.Hidden = True
.Styles("Not Sunday").Font.Hidden = True
.Styles("Normal").Font.Hidden = False

I am doing this because there are a couple of days that I need items
hidden that I need to see every other day of the week.

Thanks

"Jay Freedman" wrote:

If you select the entire row, including the row marker in the right
margin (which is visible if you display nonprinting characters with
the ¶ button), and then apply the paragraph style to that, then the
table row will hide when you set the style's Hidden attribute to
True. If you select any less than the entire row before applying the
style, then the row won't hide.

On Wed, 29 Apr 2009 18:10:06 -0700, Waitsu
wrote:

OK - I am able to hide the lines that I do not want to see
manually, i have not worked on the macro yet.

My next issue is that the text is in a table, when I hide the items
I do not want to see, I get a blank box - is there any way to hide
the table row that is empty or am I out of luck on that?

Thanks

"Jay Freedman" wrote:

On Mon, 27 Apr 2009 18:02:03 -0700, Waitsu

wrote:

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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
applying macro to a selected text only James Microsoft Word Help 4 April 17th 09 06:16 AM
Macro only selected text Greg In Atl Microsoft Word Help 2 April 26th 07 08:30 PM
HOW TO THICKEN SELECTED LINES OF A TABLE wraggedass Tables 2 July 14th 06 10:44 AM
Macro: Execute for Selected Text Only Pleonasm Microsoft Word Help 4 November 29th 05 10:55 PM
How do I set up a macro to set selected words typeface to Bold? Douglas McKibbin Microsoft Word Help 2 April 28th 05 10:17 PM


All times are GMT +1. The time now is 01:04 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"