如何实现批量替换多个word文件中的某一页
作者:dlcms 浏览量:1906 次 发布时间:2018-09-25 02:58:24
新建的页要写在("c:新建的页.doc")中。
Sub s1() '批量换第七页
On Error Resume Next
Application.ScreenUpdating = False
Dim MyPath As String, i As Integer, myDoc As Word.Document, mydoc2 As Word.Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
With Application.FileSearch
.LookIn = MyPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Visible:=False)
With myDoc
.Range(.GoTo(wdGoToPage, wdGoToNext, , 7).Start, VBA.IIf(7 >= .GoTo(wdGoToPage, wdGoToNext, , 7).Information _
(wdNumberOfPagesInDocument), .Content.End, _
.GoTo(wdGoToPage, wdGoToNext, , 8).Start)).Select
End With
'Selection.Delete
Selection.InsertFile ("c:新建的页.doc") '注意:新页需为满页,不足要换行,否则会将第八页内容搞到第七页
myDoc.Close True
Next
End If
End With
Application.ScreenUpdating = True
End Sub
Sub s1() '批量换第七页
On Error Resume Next
Application.ScreenUpdating = False
Dim MyPath As String, i As Integer, myDoc As Word.Document, mydoc2 As Word.Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
With Application.FileSearch
.LookIn = MyPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Visible:=False)
With myDoc
.Range(.GoTo(wdGoToPage, wdGoToNext, , 7).Start, VBA.IIf(7 >= .GoTo(wdGoToPage, wdGoToNext, , 7).Information _
(wdNumberOfPagesInDocument), .Content.End, _
.GoTo(wdGoToPage, wdGoToNext, , 8).Start)).Select
End With
'Selection.Delete
Selection.InsertFile ("c:新建的页.doc") '注意:新页需为满页,不足要换行,否则会将第八页内容搞到第七页
myDoc.Close True
Next
End If
End With
Application.ScreenUpdating = True
End Sub
相关阅读:
- 大疆无人机测绘原理 (2019-12-09)
- 地理地图开发工具ESRI ArcGIS Desktop (2018-09-25)
- 21个 MapGIS 实用小技巧 (2019-12-09)
- 用了这么久的GPS系统 你真的知道它是怎么运行的吗? (2019-12-09)
- 如何解决RTK与全站仪测量误差 (2017-12-25)