j.cy
03-25-2015, 01:26 AM
Hi all, I've been searching and trying for 2 weeks and haven't had a clue, hope the experts here can help
what i'm doing is, firstly, to discern english and chinese texts by replacing english texts and the space after them to red in colour,
recorded macro as follow:
Sub ReplaceNonChineseToColorRed()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = wdColorRed
With Selection.Find
.Text = "[0-9a-zA-Z]{1,50} {1,50}"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Application.DisplayAlerts = False
Selection.Find.Execute Replace:=wdReplaceAll
Application.DisplayAlerts = True
End Sub
then, find and select whole story apart from the ones with other font colours
recorded macro cannot be used per my limited understanding, anyway, the code is now, somehow, like this:
Sub FindAndSelectOccurancesWithColorAuto()
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
With Selection.Find
.Text = "^?"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Application.ScreenUpdating = True
End Sub
finally replace spaces occurred in the selection, they are supposed to be chinese spaces only
Sub ReplaceSpaces()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Application.DisplayAlerts = False
Selection.Find.Execute Replace:=wdReplaceAll
Application.DisplayAlerts = True
End Sub
obviously i'm too green to discover what goes wrong, my vba experience is just 2 weeks...
please help and thanks in advance
cheers
Jo
what i'm doing is, firstly, to discern english and chinese texts by replacing english texts and the space after them to red in colour,
recorded macro as follow:
Sub ReplaceNonChineseToColorRed()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = wdColorRed
With Selection.Find
.Text = "[0-9a-zA-Z]{1,50} {1,50}"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Application.DisplayAlerts = False
Selection.Find.Execute Replace:=wdReplaceAll
Application.DisplayAlerts = True
End Sub
then, find and select whole story apart from the ones with other font colours
recorded macro cannot be used per my limited understanding, anyway, the code is now, somehow, like this:
Sub FindAndSelectOccurancesWithColorAuto()
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
With Selection.Find
.Text = "^?"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Application.ScreenUpdating = True
End Sub
finally replace spaces occurred in the selection, they are supposed to be chinese spaces only
Sub ReplaceSpaces()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Application.DisplayAlerts = False
Selection.Find.Execute Replace:=wdReplaceAll
Application.DisplayAlerts = True
End Sub
obviously i'm too green to discover what goes wrong, my vba experience is just 2 weeks...
please help and thanks in advance
cheers
Jo