PDA

View Full Version : Help with insert zero-width spaces between last two characters of each paragraph



janaboo13
07-18-2013, 07:51 AM
Greetings experts! :hi:

I'm looking for some much needed help with code to search each paragraph marker in a document in Chinese. After finding the paragraph, I need to move the cursor left two/three characters (includes a punctuation mark and the preceding Chinese character), and then insert a zero-width, no break character. This will force at least two characters to the last line of the paragraph, which is proper Chinese formatting. Right now, I have to do this manually and inevitably will not get all of the orphans in the document.

This is a different approach from a question that I asked for help with last summer. I originally thought that I could search for the last line of all paragraphs and test to see if it had only two characters, and if so, back up and insert a soft return. When I found out about inserting a zero-width, no break character, I decided to see if I could fix this...who knew?

I've recorded a macro that achieves this, but need some help getting it to loop through the entire document. I always seem to get hung up on the looping process and making code more efficient and elegant.

You'll notice in the code that I want to start the search is in the 5th section.

Here's the code:



Option Explicit

Sub InsertZeroWidthCharacter()

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=5, Name:=""
Selection.Find.ClearFormatting
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.CorrectHangulEndings = True
.HanjaPhoneticHangul = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.InsertSymbol CharacterNumber:=8205, Unicode:=True, Bias:=0
End Sub



Sure would appreciate any help you can give me!

Thanks! Jan