Consulting

Results 1 to 6 of 6

Thread: Is there a way to "find", using the Selection or Range objects?

  1. #1

    Is there a way to "find", using the Selection or Range objects?

    Background:

    I format word documents for opening in Duxbury braille software. I use character styles in Word on certain passages that require special formatting in Duxbury. The Word styles are mapped to Duxbury styles via an intermediate file, which styles in turn perform formatting in the Duxbury file. The Word character styles do nothing except supply a style name to Duxbury.

    What I want to achieve:

    A quick way to find the last pilcrow in any series of paragraphs which have been given a character style in Word, and then clear all character formatting from that one pilcrow if it has any.

    This can be done manually when applying the style, but it's slow.

    The unstyled pilcrow prevents the bleeding of styles across paragraphs during a long and complicated conversion process which I use to prepare the file for opening by Duxbury. Without it, heading styles can bleed backward into preceding paragraphs.

    So in short: is there a way to "find", using the Selection or Range objects, the last pilcrow in what may be one or many paragraphs to which a character style has been applied? and then clear that style?
    Sonja Stephens

  2. #2
    VBAX Regular
    Joined
    Jan 2022
    Posts
    16
    Location
    Hi! Since your question is not quite specific (at least, to me), I suggest the following simple code:
    Sub Change_Paragraph_Style()
    'In the selected range, change the style of the specifically-styled paragraphs.
    
    Dim oPar As Paragraph
    Dim StyleFind As String
    Dim StyleNew As String
    
       StyleFind = InputBox("Enter the Style to find", "FIND STYLE")
       StyleNew = InputBox("Enter the Style to replace with", "NEW STYLE")
    
       For Each oPar In selection.range.Paragraphs
         If oPar.Style = ActiveDocument.Styles(StyleFind) Then
           oPar.Style = ActiveDocument.Styles(StyleNew)
         End If
       Next oPar
    End Sub
    Notes:
    1) Style name is case-insensitive;
    2) If you want to reset/clear all formatting, enter 'Normal' or 'normal' (w/o "'") in the NewStyle box.
    Last edited by Vladimir; 01-23-2024 at 04:16 AM.

  3. #3
    VBAX Regular
    Joined
    Jan 2022
    Posts
    16
    Location
    If the code in the previous post is not what you want, please, clarify your request.

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    @Vladimir. My very limited knowlege of Word is coming to bear. I thought "^p" found all pilcrows? <--- scratch this question.

    Having quick browse on the net, I was unable to find anything that differentiated between styled and non styled pilcrows, although I did see briefly some websites talked about two different pilcrows (one with straight pipes and the other with curved pipes, I didn't understand it so didn't read on further).
    Last edited by Aussiebear; 01-23-2024 at 04:04 AM. Reason: Should have thought about it a bit more before typing
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Lock the doors people, there's a missing post on the loose.....
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Regular
    Joined
    Jan 2022
    Posts
    16
    Location
    Hi, Aussiebear! I've changed my previous post proposing a different very simple approach without searching for pilcrows. I hope that is what is needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •