当前位置: 首页 >> 地理信息系统 >>

如何实现批量替换多个word文件中的某一页

0
新建的页要写在("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


Powered by DLKIT 开发版 © 2011-2012 DLCMS.NET Inc.
Copyright © 2017-2023 南充辰汐科技有限公司

住所:南充市顺庆区油院路30号南充高新孵化园内

联系人:刘义君

联系电话:18781755505(微信同号)

QQ:23424830

Email : 23424830@QQ.com