【问题标题】:Macro runs fine when in slide editor view but not slideshow view宏在幻灯片编辑器视图中运行正常但不是幻灯片视图
【发布时间】:2018-08-04 02:55:58
【问题描述】:

我有一个宏,当我到达特定幻灯片时应该运行该宏。现在,当我在幻灯片编辑器视图中而不是在实际幻灯片视图中时,宏可以完美运行。但是当我在幻灯片查看时,宏只运行一半的代码。我一生都无法弄清楚,任何帮助将不胜感激!

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

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

    如果以后有人用与我的代码类似的代码遇到这个问题,那是 select 语句把它扔掉了。这是我添加图像的更新代码:

    使用 ActivePresentation.Slides(7).Shapes

      .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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      相关资源
      最近更新 更多