PowerPoint / VBA: как заменить заполнитель изображением при загрузке слайдов - PullRequest
0 голосов
/ 14 декабря 2011

Я пытаюсь заставить PowerPoint загружать изображения для замены заполнителей при каждом изменении слайда. У меня работает код, который меняет заполнители с изображениями с локального диска или URL. Но он не будет работать на событии OnSlideShowPageChange() (упомянуто здесь ). Не имея опыта работы с VB / VBA, я понятия не имею, почему, поскольку он не дает никаких ошибок. Я знаю, что к событию обращаются, потому что, если я добавлю в него MsgBox() -функцию, оно отобразится.

Код замены изображения:

Dim strPicName As String
Dim shp As Shape
Dim sglShapeLeft As Single
Dim sglShapeTop As Single
Dim sglShapeHeight As Single
Dim sglShapeWidth As Single

'Get the name of the shape (image)
'Provided this is the only shape on the slide
'Since I don't think you can use the ME. keyword to reference an impage from Powerpoint VBA
'(Me.shape.Name)
For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    strPicName = shp.Name
Next shp

'Select the Image
ActiveWindow.Selection.SlideRange.Shapes(strPicName).Select
'Get the Left and Top starting points and width and height
sglShapeLeft = ActiveWindow.Selection.SlideRange.Shapes(strPicName).Left
sglShapeTop = ActiveWindow.Selection.SlideRange.Shapes(strPicName).Top
sglShapeHeight = ActiveWindow.Selection.SlideRange.Shapes(strPicName).Height
sglShapeWidth = ActiveWindow.Selection.SlideRange.Shapes(strPicName).Width
'Delete the Image
ActiveWindow.Selection.ShapeRange.Delete
'Insert a new Image at the same starting points as the previous image
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="<picturePath/url>", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=sglShapeLeft, Top:=sglShapeTop, Width:=sglShapeWidth, Height:=sglShapeHeight).Select

For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    strPicName = shp.Name
Next shp

ActiveWindow.Selection.SlideRange.Shapes(strPicName).IncrementRotation 276#

Любая помощь приветствуется

1 Ответ

1 голос
/ 16 декабря 2011

ActiveWindow недоступно в режиме просмотра слайдов.

Попробуйте вместо этого

Dim sld As Slide
Set sld = ActivePresentation.Slides _
    (ActivePresentation.SlideShowWindow.View _
    .CurrentShowPosition)

Set shp = sld.Shapes(1)

With shp
    sld.Shapes.AddPicture(FileName:="<picturePath/url>", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height).IncrementRotation 276#
    .Delete
End With

Кстати, отладка и исключения не поддерживаются в событии OnSlideShowPageChange.В качестве простого подхода поместите MsgBox после каждой строки кода, чтобы увидеть, где останавливается выполнение.

...