【发布时间】:2020-02-05 23:33:08
【问题描述】:
我正在尝试编写一个宏来查找单词(表 1-1),然后查找文档中的下一个单词(表 2-1)并将表 1-1 格式化为实际的单词表。我已经弄清楚了那部分并且工作得很好。
这是我似乎无法开始工作的循环部分。我希望它移动到下一个范围以找到从(表 2-1)到(表 3-1)的表集。我希望它对文档中的每个表都执行此操作,直到它遍历所有表。
代码如下:
Sub FindTableFormatIt()
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim strTheText As String
Dim tableEach As Table
Dim i As Long
For i = 1 To 100
Set rng1 = ActiveDocument.Range
If rng1.Find.Execute(FindText:="Table") Then
Set rng2 = ActiveDocument.Range(rng1.End, ActiveDocument.Range.End)
If rng2.Find.Execute(FindText:="Table") Then
Set rng3 = ActiveDocument.Range(rng1.Start, ActiveDocument.Range.End)
ActiveDocument.Range(rng3.Start, rng2.Start).ConvertToTable
End If
End If
Next i
End Sub
这是word文档的样子。
Table 1-1
Q1. When there is an election for president do you always vote, almost always vote, vote most of the time, vote some of the time, hardly ever vote, or never vote?
Total
-------
Total 600
Always 87.8
Almost always 6.0
Most of time 4.3
Sometimes 2.0
Table 2-1
Q2. For statistical purposes, what is your age?
Total
-------
Total 600
18-34 21.2
18-29 13.5
30-34 7.7
35-44 18.1
35-39 8.8
40-44 9.4
45-54 16.4
55-64 18.6
55-60 10.9
61-64 7.6
65+ 25.7
Mean 50.0
Table 3-1
Q3. Gender:
(NET DIF 1 - Percent male minus percent female)
Total
-------
Total 600
Male 48.0
Female 52.0
NET DIF 1 -4.0
Table 4-1
Q4. If you had to label yourself, would you say you are a liberal, a moderate or a conservative in your political beliefs?
(NET DIF 1 - Percent Conservative minus percent Liberal)
Total
-------
Total 600
Liberal 28.4
Very Liberal 12.9
Somewhat Liberal 15.4
Moderate 31.1
Conservative 35.3
Somewhat Conservative 14.7
Very Conservative 20.6
DK/Refused 5.3
NET DIF 1 7.0
【问题讨论】: