在幻灯片编辑器视图中但不在幻灯片显示视图中时,宏运行良好

时间:2018-08-03 12:03:19

标签: vba powerpoint powerpoint-vba

我有一个应该在转到特定幻灯片时运行的宏。现在,当Im在幻灯片编辑器视图而不是实际的幻灯片显示视图中时,宏可以完美运行。但是当我在幻灯片视图中查看时,宏仅运行一半的代码。我一生都无法解决,将不胜感激!

Private Sub NewMonthButton_Click()

Dim s As Shape
Dim Month As String

 'NewMonthSelection is a text box from a user form
Month = NewMonthSelection.Text

'Delete any images on the slide
For Each s In ActivePresentation.Slides(7).Shapes
    If s.Type = 13 Then s.Delete '13 is msoPicture
Next

   'Add first picture
  ActivePresentation.Slide(7).Shapes.AddPicture( _
   FileName:="C:\Users\Public\Pictures\Sample Pictures\" & Month & "1.PNG", _
   LinkToFile:=msoFalse, _
   SaveWithDocument:=msoTrue, Left:=80, Top:=120, _
   Width:=550, Height:=180).Select

   'This is where the code quits, it adds the first picture but not the second
   'unless its in the slide editor view
  ActivePresentation.Slide(7).Shapes.AddPicture( _
   FileName:="C:\Users\Public\Pictures\Sample Pictures\" & Month & "2.PNG", _
   LinkToFile:=msoFalse, _
   SaveWithDocument:=msoTrue, Left:=80, Top:=310, _
   Width:=550, Height:=180).Select

NewMonthSelection.Text = ""

End Sub

1 个答案:

答案 0 :(得分:0)

如果将来有人用与我类似的代码遇到这个问题,那就是select语句将其抛出。这是我添加图像的更新代码:

具有ActivePresentation.Slides(7).Shape

  .AddPicture _
   FileName:="C:\Users\Public\Pictures\Sample Pictures\" & Month & "1.PNG", LinkToFile:=False, SaveWithDocument:=True, Left:=80, Top:=120, Width:=550, Height:=180


  .AddPicture _
    FileName:="C:\Users\Public\Pictures\Sample Pictures\" & Month & "2.PNG", LinkToFile:=False, SaveWithDocument:=True, Left:=80, Top:=310, Width:=550, Height:=180
End With