vba 批量修改页眉
主要问题:
批量修改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 名称,每一个文档都不是固定的,不知道该如何替换为其他方法代替。。望指教。。谢谢。。