'-----------------------编号批量前进---------------------------------------
Sub 批量前进()
'
' 批量后退,这个宏用于将出版书籍时对编号(如图像编号、章节编号)进行整体调整
' 作者 陈刚 glchengang@yeah.net
'
Dim prefix As String
Dim startI As Integer
Dim endI As Integer
Dim spaceI As Integer
prefix = InputBox("前缀", "", "图9.")
startI = InputBox("开始")
endI = InputBox("结束", "", "100")
spaceI = InputBox("前进值", "", "1")
Set myRange = ActiveDocument.Content
For i = startI To endI Step 1
myRange.Find.Execute FindText:=prefix & i, ReplaceWith:=prefix & (i - spaceI), Replace:=wdReplaceAll
Next i
End Sub
'-----------------------错别字替换,用词的统一---------------------------------------
Sub 错别字替换()
'
' 作者 陈刚 glchengang@yeah.net
'
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="做为", ReplaceWith:="作为", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="”→“", ReplaceWith:="→", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="->", ReplaceWith:="→", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="点击", ReplaceWith:="单击", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="部分", ReplaceWith:="部份", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="其它", ReplaceWith:="其他", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="右键快捷菜单", ReplaceWith:="右键菜单", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="附带光盘", ReplaceWith:="随书光盘", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="教师", ReplaceWith:="老师", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="图象", ReplaceWith:="图像", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="xml映射文件", ReplaceWith:="XML映射文件", Replace:=wdReplaceAll
myRange.Find.Execute FindText:="eclipse3.1M4\", ReplaceWith:="", Replace:=wdReplaceAll
End Sub
'----------------------将一个总文件按章节来分成小文件--------------------------------------------------
Sub 分章()
'
' 作者 陈刚 glchengang@yeah.net
'本书一共26章,分四篇,并且每一篇一个目录。在文档后面有一个没有内容的第27章做结束标志。
'在使用此宏分章时,需要将光标定位在第一章的开头和目录的结尾
'
' 得到当前路径
Dim path As String
path = ActiveDocument.path '获得当前打开文档(总文档)的绝对路径
'生成“目录”
Selection.Find.ClearFormatting
Selection.Find.Text = "第1章"
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Cut
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
ChangeFileOpenDirectory path
ActiveDocument.SaveAs FileName:="目录.doc"
ActiveWindow.Close
'生成其他文件
'得到各章的保存目录。共四个目录
For i = 2 To 27
If (i >= 2 And i <= 6) Then
savePath = path & "\第一篇 起步篇(1-5)\"
ElseIf (i >= 7 And i <= 17) Then
savePath = path & "\第二篇 SWT_JFace篇(6-16)\"
ElseIf (i >= 18 And i <= 23) Then
savePath = path & "\第三篇 插件开发篇(17-22)\"
ElseIf (i >= 24 And i <= 27) Then
savePath = path & "\第四篇 WEB开发篇(23-26)\"
End If
Selection.Find.ClearFormatting
Selection.Find.Text = "第" & i & "章"
Selection.Find.Execute '开始查找
Selection.MoveLeft Unit:=wdCharacter, Count:=1 '相当于按“<-”光标键
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend '相当于按Ctrl+Shift+Home
Selection.Cut '剪切
Documents.Add DocumentType:=wdNewBlankDocument '新建一个空白文档
Selection.PasteAndFormat (wdPasteDefault) '按原格式粘帖
ChangeFileOpenDirectory savePath '设定文件保存目录
ActiveDocument.SaveAs '保存
ActiveWindow.Close '关闭文档
Next i
End Sub
后记:很奇怪CSDN的博客没有粘帖代码的功能。在Java视线的论坛可以粘帖代码,代码关键字都会变颜色,和设置粗体,看起来舒服很多。