主要问题:
   批量修改N个word文档的页眉中的图片。(注:第一页中的页眉和第二页中页眉图片不一样,剩下页与第一页相同)
我的解决方法:
   录制了一个文档的修改图片过程的步骤:
  1:选中修改页眉,然后选中第一页的页眉中的图片删掉,插入新的图片;
  2:选中第二页中的页眉中的图片删掉,插入新的图片,关闭修改页眉。
   录制代码如下:
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    
    Selection.HeaderFooter.Shapes("Picture 2").Select '原来图片
    Selection.ShapeRange.Delete
    Selection.InlineShapes.AddPicture FileName:= _
        "D:\test1.jpg", LinkToFile:=False, _
        SaveWithDocument:=True
   '要替换的图片
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:="     "
    
    Selection.HeaderFooter.Shapes("Picture 10").Select  '原来图片
    Selection.ShapeRange.Delete
    Selection.InlineShapes.AddPicture FileName:= _
        "D:\test2.jpg", LinkToFile:=False, _
        SaveWithDocument:=True
   '要替换的图片
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument上边红色部分,分别为原来图片,要替换的图片;
遇到的问题:
   原来图片的Selection.HeaderFooter.Shapes("Picture 10").Select : Picture 10 名称,每一个文档都不是固定的,不知道该如何替换为其他方法代替。。望指教。。谢谢。。

解决方案 »

  1.   

    如果每页页眉只有一张图片的话,那么直接用headerfooter.shapes(1).select 不就完了。页脚同理。
    如果有多张图片,那么先看看.shapes.count,然后替换哪个就用其索引号来选中替换。
      

  2.   

    Selection.HeaderFooter.Shapes(0或1到Selection.HeaderFooter.Shapes.Count).Select 
    不用命名索引,改用数字索引。不知道行不行。
      

  3.   


       ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture ("D:\test2.jpg")我现在直接添加图片的。。不删掉了。。然后覆盖掉了。