Attribute VB_Name = "PatentTranslationMacros" Sub Sequence() Dim regEx, Match, Matches ' Get the active word document Set objWdDoc = Word.Application.ActiveDocument ' Set our range to be the entire document contents Set objWdRange = objWdDoc.Content ' To be used for the result string Dim Result As String ' Create a regular expression object. Set regEx = CreateObject("VBScript.RegExp") 'Show our form NumberInsert.Show If NumberInsert.Tag Then ' Get the value of the string we want to find from the form regEx.Pattern = NumberInsert.FindStr.Value ' Set case sensitivity. regEx.IgnoreCase = False ' Set global applicability to false. This was the odd part since ' no examples on the internet, that I could find, used ' Globabl = False. regEx.Global = False ' A little silly but we have to use something to catch the return value from MoveStart Dim temp As Long Dim length As Long, repStart As String, repEnd As String ' How many digits to show, retrieved from the form and converted to Long length = CLng(NumberInsert.NumberLength.Value) ' the replacement string for the portion BEFORE the inserted number repStart = NumberInsert.ReplaceStart ' the replacement string for the portion AFTER the inserted number repEnd = NumberInsert.ReplaceEnd Dim realIndex As Long Dim i As Integer ' For our step counter i = 0 Do ' Get the first match (Global = False, remember) Set Matches = regEx.Execute(objWdRange) ' If there isn't a match, Exit If Matches.Count = 0 Then Exit Do End If ' Get the first match from the MatchCollection. Set Match = Matches(0) ' Increment our counter. Since we're starting from 1 we increment before we ' change the value i = i + 1 ' Convert the characters to full width Japanese characters ' String(Length, "0") gives us the format pattern for the number tStr = StrConv(Format(i, String(length, "0")), vbWide, 1041) ' regex replace using the found value and our pattern from the form Result = regEx.Replace(Match.Value, repStart & tStr & repEnd) ' add the index for the range start and the match index which only considers ' its position within the range realIndex = objWdRange.Start + Match.FirstIndex ' Insert our result into the range objWdDoc.Range(realIndex, realIndex + Len(Match.Value)).Text = Result ' move the start point on our range by the length ' of our replacement plus the position within the ' range, plus one temp = objWdRange.MoveStart(wdCharacter, Match.FirstIndex + Len(Match.Value) + 1) Loop End If End Sub