Thanks for the replies guys! I guess it helps if I attach the document. Macropod, I can't seem to get yours to work... I tried changing "^13" into "^l", but still no luck.
Regarding line wraps vs forced; I guess I'm not sure what the definitions of these are. They are not 'wraps' in the sense that the text got to the right edge, then got wrapped automatically by Word, but they are the wrap that you get if you use "^l" in the Replace box. I guess maybe that's a "line return" and the "^13"one is a "new paragraph?"
Anyway, as I look closer at my post, I think it's my first group "([ ]@)" that is the problem. I wanted it to be "zero or more spaces" but I realize now this it is "one or more spaces." In the world of regex (which I'm not an expert of!) you can tell the regex to capture a sub group if it's there, but still go ahead and capture the the other group even if it's not. I guess maybe that's not possible with Word(?) It's worth noting that I did try "([ ]{0,})" but that is apparently not valid.
So my goal is to make this as flexible as possible. Most of the time, it will just be applied to a list of items that don't have any spaces at the beginning of lines. But *sometimes* there might be items that have one or two spaces. In those cases, they will be interspersed with no-beginning-space items (like in the attached). Usually they will have the 'line return' ^l at the ends.
My current system is that I have a function
Code:
Sub DoFindClean(FindText As String, ReplaceText As String, vWrap As String, vWild As String)
'This module gets called from the Text Cleaner code
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = FindText
.Replacement.Text = ReplaceText
.Forward = True
.Wrap = vWrap
.MatchWildcards = vWild
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
that gets called by a bunch of different subtools in my user form tool.
Among those tools is the thing I'm trying to troubleshoot.
Code:
Private Sub cmdLeftPad_Click()
Call DoFindClean("([!^13]{1,})", (txtPadding.Value) & "\1", 0, 1)
End Sub
Private Sub cmdRightPad_Click()
Call DoFindClean("([!^13]{1,})", "\1" & (txtPadding.Value), 0, 1)
End Sub
But I'm thinking that I might need to have a mulitstep bit of code rather than calling the function... Something like
Assess each line
If first char of line = space
Then first Find string.
Else second find string.
I actually had considered that, but I don't think that wdTextLine is an object.
On a related note: It would also be excellent if I could detect the second-to-the-left character of each line. That way, if the text is as below (no spaces at line starts), it could differentiate the main ALLCAPS ones and the Word Case sub-items, and process them differently.
Quote:
READING COMPREHENSION
Passage Comprehension
Reading Recall
MATHEMATICS
Applied Problems
Calculation
|
EDIT: The second bit of code in this post is from my current working set up. It only works if no lines start with a space though--otherwise it fails.