PDA

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



Whathim65
01-23-2024, 12:42 AM
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?

Vladimir
01-23-2024, 02:16 AM
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.

Vladimir
01-23-2024, 03:55 AM
If the code in the previous post is not what you want, please, clarify your request.

Aussiebear
01-23-2024, 03:57 AM
@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).

Aussiebear
01-23-2024, 04:07 AM
Lock the doors people, there's a missing post on the loose.....

Vladimir
01-23-2024, 04:09 AM
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.