主题更改后,Powerpoint VBA在布局上更改图片

时间:2015-11-26 16:44:33

标签: vba powerpoint powerpoint-2010

我有一个Powerpoint模板,标题幻灯片布局图片。用户可以打开自定义Userform来更改图片(VBA删除旧图片,然后插入选择图片)。

但是在用户更改主题后,后续图片更改不可见。这是我所能看到的,因为图片仅在原始主题的标题幻灯片布局中更改。更改主题实际上会添加一个新的幻灯片母版。

有没有办法在我的演示文稿中更改每个幻灯片母版标题幻灯片布局上的图片?

这是VBA代码:

    Set shp = ActivePresentation.SlideMaster.CustomLayouts(1).Shapes(strShapeName)

    With shp
      sngTop = .Top
      sngLeft = .Left
      sngWidth = .Width
      sngHeight = .Height
      .Delete
    End With

    Set shp = ActivePresentation.SlideMaster.CustomLayouts(1).Shapes.AddPicture _
      (strFullFileName, msoFalse, msoTrue, _
      sngLeft, sngTop, sngWidth, sngHeight)

    With shp
      .ZOrder msoSendToBack
      .Name = strShapeName
    End With

感谢您的任何建议。

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

Dim oDes As Design
Dim shp As Shape

For Each oDes In ActivePresentation.Designs
    Set shp = oDes.SlideMaster.CustomLayouts(1).Shapes(strShapeName)

    With shp
      sngTop = .Top
      sngLeft = .Left
      sngWidth = .Width
      sngHeight = .Height
      .Delete
    End With

    Set shp = oDes.SlideMaster.CustomLayouts(1).Shapes.AddPicture _
      (strFullFileName, msoFalse, msoTrue, _
      sngLeft, sngTop, sngWidth, sngHeight)

    With shp
      .ZOrder msoSendToBack
      .Name = strShapeName
    End With

    Next    ' Design