[RESOLVED] Word Macro - replace hard returns
Hi,
I'm new to VB but am writing a macro which is adding xml tags around Word content.
I need to change a hard return with the text <lineBreak/>, but get an error each time.
I have tried to search for "^|", and have also tried to search for Chr(10), but nothing seems to work. Am I using the wrong code to detect the shift-enter key combination?
If I change the search to "^p" or Chr(13) it works fine.
Many thanks
pramenjatjek
Re: Word Macro - replace hard returns
Welcome to the Forums.
"^p" or "Chr(13) & Chr(10)" is the solution. Did you need more help with this?
Re: Word Macro - replace hard returns
Thank you... and yes please :)
I tried the combination of Chr(13) & Chr(10), but it still doesn't work. This is the sub
With ActiveDocument.Content.Find
.ClearFormatting
.Text = Chr(13) & Chr(10)
With .Replacement
.ClearFormatting
.Text = "<lineBreak/>"
End With
.Execute Replace:=wdReplaceAll, Format:=True
End With
Thanks again,
Pramenjatjek
Re: Word Macro - replace hard returns
Ok, so what do you mean by "doesnt work"?
What is the error message?
Re: Word Macro - replace hard returns
What I expected to happen was for the linebreak arrow (left pointy arrow) to be replaced with the word <lineBreak/>. But instead, nothing happens. It runs, but it appears to ignore it altogether.
When I did a search in the Word doc itself for the left pointy arrow to see that it can be detected, the code that it searches for is ^|. When I put that in the .Text line, it gives the error "Run-time error '5625'; and a little box.
Hopefully this explanation helps?
Pramenjatjek
Re: Word Macro - replace hard returns
Do you mean this character --> ΒΆ
Re: Word Macro - replace hard returns
No, the other one which leaves no space between 2 lines. It looks like a left-pointing arrow with a vertical hook at the right-side of the arrow.
Same function as <br> in html....
Re: Word Macro - replace hard returns
That sounds like the Enter key but I dont see it in word 2003. Which version are you running?
An Enter key is actually the chr(13) and Chr(10) char combination.
Re: Word Macro - replace hard returns
It's Word 2003, and the VB version is Microsoft Visual Basic 6.3.
It's the combination of the shift + enter key that I'm trying to capture.
Re: Word Macro - replace hard returns
Ah, a Text Wrapping Break is what its called. sorry, just really tired tonight (trying to recover from a cold).
There has to be a short cut equilivalent for it just like the paragraph "^p". I'll see what I can find.
Re: Word Macro - replace hard returns
Thanks so much :) and get well soon.
Re: [RESOLVED] Word Macro - replace hard returns
This is the one that did the trick :)
With ActiveDocument.Content.Find
.ClearFormatting
.Text = ChrW(11)
With .Replacement
.ClearFormatting
.Text = "<lineBreak/>"
.Font.Color = wdColorGray40
End With
.Execute Replace:=wdReplaceAll, Format:=True, MatchCase:=True, MatchWholeWord:=True
End With