Add Watermark to PowerPoint Slide from Excel

好久不见. 提交于 2019-12-13 05:06:15

问题


I am trying to add a watermark to a PowerPoint slide from Excel with VBA and don't know where to start. I have searched on Google and found nothing. There is one question on Stackoverflow that helped a little but I couldn't follow it. I am wondering if someone could refer me to somewhere or point me in the right direction? Again, I just want to add a watermark to one of the slides in Master View. Thanks!


回答1:


To change a slide in Master View, you can work with the CustomLayouts collection.

Note that you'll have to refer to a specific CustomLayout by its index, and not its Name, as this question points out.

This example code

  • creates or gets a PowerPoint instance
  • creates a new Presentation
  • copies Picture 1 and pastes it in the Shapes collection of the first CustomLayout, which for me is the Title Slide Layout.

I assume from here you can modify its size/position or make any other desired changes.

Sub AddWatermark()
    Dim wmark As Shape: Set wmark = ThisWorkbook.Sheets("Sheet1").Shapes("Picture 1")
    Dim PPT As PowerPoint.Application
    Dim pres As PowerPoint.Presentation

    On Error Resume Next
        Set PPT = GetObject(, "PowerPoint.Application")
    On Error GoTo 0

    If PPT Is Nothing Then
        Set PPT = New PowerPoint.Application
    End If

    PPT.Visible = True
    Set pres = PPT.Presentations.Add

    wmark.Copy
    pres.SlideMaster.CustomLayouts(1).Shapes.Paste

End Sub

My Original Watermark


Title Slide Layout showing applied watermark



来源:https://stackoverflow.com/questions/51505389/add-watermark-to-powerpoint-slide-from-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!