这个概念是使用两个数组两次:I) 将 [1] 替换为 @@@[1]@@@, [2] for @@@[2]@@@, ..., [n] for @@@[n]@@@;II) 将 @@@[1]@@@ 替换为 [11],将 @@@[2]@@@ 替换为 >[12], ..., @@@[n]@@@ for [n+10].更深刻的观点:1.1) 从 [1] 到 [n] 创建 searchArray.你可以用这个.http://textmechanic.com/generate-list-numbers/.数字前缀:[",后缀:]",加入:,".1.2) 使用相同的工具创建带有前缀@@@"和后缀@@@"的replaceArray(为了唯一性),即@@@[1]@@@, @@@[2]@@@, .. @@@[n]@@@.>1.3) 将 searchArray 替换为 replaceArray.[改编附件中的代码].2.1) 创建searchArray,同1.2)2.2) 使用工具 http://textmechanic.com/generate-list-numbers/ 从 [10] 到 [n+10] 创建 replaceArray.IE.[10], [11], ... [n]2.3) 将 searchArray 替换为 replaceArray.[改编附件中的代码].附件选项显式子 replaceArrayForArray()''创建数组使用前缀后缀和替换工具 http://textmechanic.com/''findArray = Array("[1]", "[2]", "[3]")replArray = Array("@@@[1]@@@", "@@@[2]@@@", "@@@[3]@@@")对于 i = 0 到 UBound(findArray)选择.查找.清除格式Selection.Find.Replacement.ClearFormatting使用选择.查找.Text = findArray(i).Replacement.Text = replArray(i).Forward = 真.Wrap = wdFindContinue.Format = 假.MatchCase = 真.MatchWholeWord = 假.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = False结束于Selection.Find.Execute replace:=wdReplaceAll接下来我结束子PS: 为什么不将 [1] 替换为 [11]?但是我们必须首先将 [1] 替换为 @[1]@ 然后将 @[1]@ 替换为 [11]?因为在循环的 10 次迭代中,我们将有两个 [11],它们都将变成 [21];然后三个 [21] 将变成 [31] 等等.PPS:如果您想复制和粘贴答案,请使用两部分代码:http://codepad.org/sZEG78ak.但是你仍然需要像上面提到的那样扩展数组.I am trying to make a MS-word Macro to increment all numbers in the word document which are within brackets, eg original numbers [1] [2] [3] [4] , after incrementing all numbers by 10, above numbers will be changed to [11] [12] [13] [14]I'm stuck in the code below and not familiar with VBA before. Can anyone suggest, what to add in code below to perform above macro?? Sub IncrementNumbers()'' IncrementNumbers Macro''Application.ScreenUpdating = FalseDim RngStory As Range, StrStart As String, StrEnd As StringStrStart = "["StrEnd = "]"Set RngStory = ActiveDocument.RangeWith RngStory.FindSome code here to increment and replace numbersSet RngStory = NothingApplication.ScreenUpdating = TrueEnd Sub 解决方案 There is another option. I hope you are familiar with the concept of arrays (in any language). Just keep in mind that in VBA arrays are inside brackets ("[1]", "[2]"). If not, it won't be a problem.If your goal is to replace [1] for [11], [2] for [12], ... [n] for [n+10] then you may do the following.Please, consider to look here. The answers are alike. Changing numbering in word using VBAThe concept is to work with two arrays two times: I) replace [1] for @@@[1]@@@, [2] for @@@[2]@@@, ..., [n] for @@@[n]@@@; II) replace @@@[1]@@@ for [11], @@@[2]@@@ for [12], ..., @@@[n]@@@ for [n+10].More profound view:1.1) Create searchArray from [1] to [n]. You can use this. http://textmechanic.com/generate-list-numbers/. Prefix numbers with: "[", suffix with: "]", Join with: ",".1.2) With the same tool create replaceArray with prefix "@@@" and sufix "@@@" (for uniqueness), i.e. @@@[1]@@@, @@@[2]@@@, .. @@@[n]@@@.1.3) Replace searchArray for replaceArray.[Adapt code from Annex].2.1) Create searchArray, it is the same as in 1.2)2.2) With the tool http://textmechanic.com/generate-list-numbers/ create replaceArray from [10] to [n+10]. I.e. [10], [11], ... [n]2.3) Replace searchArray for replaceArray.[Adapt code from Annex].AnnexOption ExplicitSub replaceArrayForArray()''to create array use prefixsuffix and replacing tool http://textmechanic.com/''findArray = Array("[1]", "[2]", "[3]")replArray = Array("@@@[1]@@@", "@@@[2]@@@", "@@@[3]@@@")For i = 0 To UBound(findArray) Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = findArray(i) .Replacement.Text = replArray(i) .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = True .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute replace:=wdReplaceAllNext iEnd SubPS: Why not replace [1] for [11]? But we have to firstly replace [1] for @[1]@ and then secondly @[1]@ for [11]?Because in 10 iterations through loop we will have two [11] that will both turn into [21]; then three [21] that will turn into [31] etc.PPS: Both parts of the code if you'd like to copy and paste the answer: http://codepad.org/sZEG78ak. But still you will have to expand arrays as noted above. 这篇关于MS Word 宏可增加 Word 文档中的所有数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 04:18