如何實(shí)現(xiàn)批量替換多個word文件中的某一頁
作者:dlcms 瀏覽量:1923 次 發(fā)布時間: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 = "選擇目標(biāo)文件夾"
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") '注意:新頁需為滿頁,不足要換行,否則會將第八頁內(nèi)容搞到第七頁
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 = "選擇目標(biāo)文件夾"
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") '注意:新頁需為滿頁,不足要換行,否則會將第八頁內(nèi)容搞到第七頁
myDoc.Close True
Next
End If
End With
Application.ScreenUpdating = True
End Sub
相關(guān)熱詞搜索:批量,文件,多個,如何,實(shí)現(xiàn)
相關(guān)閱讀:
- 大疆無人機(jī)測繪原理 (2019-12-09)
- 地理地圖開發(fā)工具ESRI ArcGIS Desktop (2018-09-25)
- 21個 MapGIS 實(shí)用小技巧 (2019-12-09)
- 用了這么久的GPS系統(tǒng) 你真的知道它是怎么運(yùn)行的嗎? (2019-12-09)
- 如何解決RTK與全站儀測量誤差 (2017-12-25)