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 theShapes
collection of the firstCustomLayout
, 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