|
可试试如下代码:- Sub test1()
- '将自动更正词条导出到新文档
- Dim i As Integer
- Dim aACentry As AutoCorrectEntry
-
- Documents.Add.Content.Text = "序号" & vbTab & "名称" & vbTab & "更正内容" & vbTab & "是否带格式" & vbCrLf
- For Each aACentry In AutoCorrect.Entries
- With aACentry
- ActiveDocument.Content.InsertAfter i + 1 & vbTab & .Name & vbTab
- If .RichText = False Then ActiveDocument.Content.InsertAfter .Value _
- Else .Apply ActiveDocument.Bookmarks("\endofdoc").Range
- ActiveDocument.Content.InsertAfter vbTab & Format(.RichText, "否;是") & vbCrLf
- i = i + 1
- End With
- Next
- ActiveDocument.Content.ConvertToTable(wdSeparateByTabs).Borders.Enable = True
- MsgBox "共有" & i & "条自动更正词条。"
- End Sub
- Sub test2()
- '批量添加自动更正词条
- '将带有自动更正条目的文档作为当前文档
- '将自动更正词条放在至少有三列的表格中,前三列分别为更正词条名、更正内容和是否带格式(只填是或否,否时可不填)
- '表格第一行为标题行
- Dim i As Integer
- Dim info As String
- Dim aRow As Row
- With ActiveDocument.Content
- If .Tables.Count = 0 Then Exit Sub
- If .Tables(1).Rows.Count < 3 Then Exit Sub
- For Each aRow In .Tables(1).Rows
- With aRow
- If .Index > 1 And Len(.Cells(1).Range.Text) > 2 Then
- If Left(.Cells(3).Range.Text, 1) = "是" Then
- AutoCorrect.Entries.AddRichText Name:=Replace(.Cells(1).Range.Text, Chr(13) & Chr(7), ""), _
- Range:=ActiveDocument.Range(.Cells(2).Range.Start, .Cells(2).Range.End - 1)
- Else
- AutoCorrect.Entries.Add Name:=Replace(.Cells(1).Range.Text, Chr(13) & Chr(7), ""), _
- Value:=Replace(.Cells(2).Range.Text, Chr(13) & Chr(7), "")
- End If
- i = i + 1
- End If
- End With
- Next
- End With
- MsgBox "共添加了" & i & "条自动更正词条。"
- End Sub
复制代码 |
|