使用 VBA 更改单词中的编号 [英] Changing numbering in word using VBA

查看:38
本文介绍了使用 VBA 更改单词中的编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份文件,其中有几个问题.现在,文档中有几个补充.我现在必须坐下来更改每个问题的编号.此外,还有一定的跳过模式.

I have a document in which several questions are there. Now, there are couple of additions in the document. I have to now sit and change each and every question number. Also, There are certain skip pattern.

例如: 如果 2 在 Q5 中编码,那么去问 Q6 否则跳到 Q10"

现在,如果我更改问题的编号.我变得非常难以映射和更改路由问题.

Now, if I change the numbering of the questions. I becomes really difficult to map and change the routing questions.

手动,需要太多时间.如果有任何方法可以通过 VBA 或任何方法来减少所需的手动工作,请帮助我.

Manually, It takes too much time. Please help me if there is any way through VBA or any method to minimize the manual work required.

推荐答案

我猜你的模式是 Q1、Q2、... Qn 代表问题 1、问题 2 等.

I guess your pattern is Q1, Q2, ... Qn representing Question 1, Question 2 etc.

此外,您还添加了问题 1,即 Q1.所以原来的Q1应该变成Q2,Q2变成Q3,...Qn变成Qn+1.

Moreover, you have added Question 1, i.e. Q1. So former Q1 should turn into Q2, Q2 to Q3, ... Qn to Qn+1.

如何插入 Q1 并将所有其他 Q 加一? 概念如下.

1) 半自动创建一个 findArray 和 replaceArray.

如何创建findArray:http://textmechanic.com/generate-list-numbers/.如果您有 100 个问题,请生成从 1 到 100 的数字,数字前缀为:Q";加入:,".

How to create findArray: http://textmechanic.com/generate-list-numbers/. If you have 100 questions, generate numbers from 1 to 100, Prefix numbers with: "Q"; Join with: ",".

2) 批量替换数组(Q1"、Q2"、Q3"、...Q100")用于数组(@@@Q1@@@"、"@@@Q2@@@"、"@@@Q3@@@"、..."@@@Q100@@@").循环遍历元素并将每个 findArray[i] 更改为 replaceArray[i].[改编附件中的代码]

2) Bulk replace array ("Q1", "Q2", "Q3", ... "Q100") for array ("@@@Q1@@@", "@@@Q2@@@", "@@@Q3@@@", ... "@@@Q100@@@"). Loop through elements and change each findArray[i] for replaceArray[i]. [Adapt code from Annex]

3) 在文本中插入新的 Q1.

4) 批量替换数组 ("@@@Q1@@@", "@@@Q2@@@", "@@@Q3@@@", ... "@@@Q100@@@") 用于数组(Q2"、Q3"、Q4"、...Q101").使用 http://textmechanic.com/generate-list-numbers/ 创建替换数组.循环遍历元素并将每个 findArray[i] 更改为 replaceArray[i].[改编附件中的代码]

4) Bulk replace array ("@@@Q1@@@", "@@@Q2@@@", "@@@Q3@@@", ... "@@@Q100@@@") for array ("Q2", "Q3", "Q4", ... "Q101"). Create replace array with http://textmechanic.com/generate-list-numbers/. Loop through elements and change each findArray[i] for replaceArray[i]. [Adapt code from Annex]

就是这样!

所有这一切意味着您应该知道如何使用两个数组更改元素.这是适用于三个元素的代码.

All that means that you should know how to change elements with the use of two arrays. Here is the code which works with three elements.

附件

Option Explicit
Sub replaceArrayForArray()
'
'to create array use prefix\suffix and replacing tool http://textmechanic.com/
'
'
    findArray = Array("Q1", " Q2", " Q3")
    replArray = Array("@@@Q1@@@", "@@@Q2@@@", "@@@Q3@@@@")

    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:=wdReplaceAll
    Next i
End Sub

PS:我用@@@是因为它比较少见.

PS: I use @@@ because it is rather rare.

PPS:对类似问题的回答:MS Word 宏增加word文档中的所有数字

PPS: Answer to the similar question: MS Word Macro to increment all numbers in word document

这篇关于使用 VBA 更改单词中的编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆