2011-12-14 2 views
0

スライドが変更されるたびにプレースホルダを置き換えるためにPowerPointにイメージを読み込ませようとしました。 私は、ローカルドライブまたはURLからの画像を使用してプレースホルダを変更するコードを使用しています。しかし、それはOnSlideShowPageChange()イベント(hereと記されている)で動作しません。 VB/VBAに関する事前の経験がないので、何の誤りもないので、なぜ私は考えていません。イベントにアクセスしたのは、MsgBox() -functionを入力すると表示されるためです。PowerPoint/VBA:スライドの読み込み時にプレースホルダを画像に置き換える方法

ImageReplaceコード:

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

の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を配置して、実行がどこで停止するかを確認します。

+0

これはうまくいきました。ありがとうございます:) – Esa

関連する問題