Add Watermark to PowerPoint Slide from Excel

2019-08-24 07:02发布

问题:

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