我的公司正在重塑品牌。当前的页脚图形必须替换为新的页脚图形。我知道 VBA 有一种方法可以删除旧图像并插入新图像,但我不知道该怎么做。我需要新图像位于文本后面,而不是内联。我还需要它的宽度为 8.1 x 0.21 高。位置以页面居中且位于下边距下方 -.05。有人可以帮忙吗?手动完成这一切让我发疯。
我尝试录制宏来查看我的步骤,但我想我无法在录制时右键单击?我尝试将其记录为内联形状,但即使如此,在插入形状后宏也会停止记录。所以我看不到如何格式化它。
Option Explicit
Sub ReplaceLogo()
Dim Shp, footerRng As Range, oSec As Section
Const LOGO = "D:\temp\logo.png" ' modify as needed
For Each oSec In ActiveDocument.Sections
Set footerRng = oSec.Footers(wdHeaderFooterPrimary).Range
' Remove old logo
' modify as needed, if multiple images in footer
For Each Shp In footerRng.InlineShapes
Shp.Delete
Next
For Each Shp In footerRng.ShapeRange
Shp.Delete
Next
Set Shp = ActiveDocument.Shapes.AddPicture(FileName:=LOGO, LinkToFile:=False, _
SaveWithDocument:=True, Anchor:=footerRng)
With Shp
.Top = .Top - InchesToPoints(0.05)
.Left = wdShapeCenter
.Height = InchesToPoints(0.21)
.Width = InchesToPoints(8.1)
.WrapFormat.Type = wdWrapBehind
End With
Next
End Sub
微软文档: