×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Word macro for printing pages with colored font

Word macro for printing pages with colored font

Word macro for printing pages with colored font

(OP)
Very new to programming and VBA, but I'm looking to develop a Word macro to allow me to print only those pages (e.g. of a several-hundred-page document) that contain text of a particular color font (e.g. red). I have an idea of how to execute some of the required elements (finding all pages with red font, identifying and returning the page number(s) of a selection) but that's as far as I've got. Thoughts greatly appreciated.

RE: Word macro for printing pages with colored font

Ok, if yoiu've figured out how to find all the necessary page numbers then it is about as easy as:

ActiveDocument.PrintOut Background:=False, Range:=wdPrintRangeOfPages, Pages:="1,7,11-17,22" ' pages just an example - this is where you'd build your own page selection string from the pages you have identified

RE: Word macro for printing pages with colored font

Paul, the OP only posted this here because he was advised to!

RE: Word macro for printing pages with colored font

(OP)
Haha, what a stir! Just to say - thanks very much strongm for the reply. I think identifying and 'building' a selection is perhaps the bit I'm struggling with, but I acknowledge this appears to be a fairly basic element for which there is plenty of guidance elsewhere. I'll go away, do my homework and have a play, and will come back with more specific questions as and when...

RE: Word macro for printing pages with colored font

Ah, I assumed that "I have an idea of how to execute … finding all pages with red font, identifying and returning the page number(s)" mean you had that bit done!

I feel I should probably point out here that Word is a word processor, not a page layout program, so its concept of a page is somewhat hazy and it provides few reliable methods of dealing with a document on a page by page basis. That being said, try the following to build your page list

CODE

Public Function GetPageSet() As String
    Dim myPage As Page
    Dim myRect As Rectangle
    Dim PageSet As String
     
    For Each myPage In ActiveDocument.ActiveWindow.Panes(1).Pages
        For Each myRect In myPage.Rectangles
            With myRect.Range.Find
                .ClearFormatting
                .Font.Color = wdColorRed
                .Text = ""
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = True
                .MatchCase = False
                .MatchWholeWord = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
                .Execute
                If .Found Then
                    PageSet = PageSet & myRect.Range.Information(wdActiveEndPageNumber) & ","
                    Exit For
                End If
            End With
        Next
    Next
    If PageSet <> "" Then GetPageSet = Left(PageSet, Len(PageSet) - 1)
End Function 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close