Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing all hidden text markers code help

Status
Not open for further replies.

sonname

Programmer
May 18, 2001
115
US
Here is a snippet of code that I have.

Dim w As Range

For Each w In ActiveDocument.Words
If InStr(1, w, "-<[lb]>") = 1 Then
w = Replace(w, "-<[lb]>", "")
w.Font.ColorIndex = 3 'for, say, RED
End If

Next

What I want to do is remove the dash and the hidden line break and replace it with nothing and color the word. For example if I have the word "pro-<[lb]>bably", note that this is what the word looks like when all hidden markers are showing. The problem is that it looks like my code is looking for that <[lb]> literally and doesn't find that condition at all. I want to end up with the word "probably" colored without the dash and the hidden line break. Is there a way to do this?

Thanks
 
Sorry, the <[lb]> is the manual line break in word. The thing is that in my document, I have some manual line breaks inserted where I have hyphenated words, for example I have words that are hyphenated and followed by a line break, so I am trying to take out the hyphen and the line break at the same time. So for example a word like "pro-bably" would become probably. Is there a way for me to do this? Thanks
 
You could do a "Search/Replace" for this "-^l", whereas "^l" is the Word "character" for manual line break.

However, be warned: some hyphens may have to stay, such as e.g. "well-documented features". You don#t want that to become "welldocumented", I suppose.

You might want to replace one by one instead of globally.

[blue]Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates[/blue]
 
MakeItSo, I understand that it would change it for the whole document, this is why I want to change the color of the word so that the user can verify it. Here is the code, it doesn't seem to find the line breaks. Am I doing something wrong?

Dim w As Range

For Each w In ActiveDocument.Words
If InStr(1, w, "-^l") = 1 Then
w = Replace(w, "-^l", "")
w.Font.ColorIndex = 3 'for, say, RED
End If

Next
 
Hi Sonname,

OK. I haven't managed to color the entire word, but at least the characters before and after hyphen and line break, then remove hyphen and line break, leaving the manipulated word with two letters colored.
Would that suffice?

I was lazy and did it with the macro recorder... :p
Code:
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "?-^l?"
        .Replacement.Text = ""
        .Replacement.Font.Color=wdColorRed
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "-^l"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

[blue]Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top