Powerpoint宏在幻灯片放映中不起作用

时间:2018-07-20 18:48:54

标签: vba powerpoint powerpoint-vba

有人可以帮我解决这个问题吗?我找到了一个从PowerPoint第一页拍摄快照的脚本。当我在普通视图中运行宏时,它起作用。但是当我使用操作按钮(将其超链接到创建的宏)并在幻灯片放映时单击它时,没有任何操作。 我希望每次单击幻灯片上的“操作”按钮时,它都能从演示文稿视图中获取快照。.

这是脚本(我没有任何编程知识)

Sub SaveCurrentSlideAsJpg()
Dim imagePath As String
Dim slideNum As Integer
  imagePath = "C:\JPG\"
  slideNum = ActiveWindow.Selection.SlideRange(1).SlideIndex


If Dir(imagePath & ActivePresentation.Name & "_" & slideNum & ".jpg") <> ""        
Then
Kill imagePath & ActivePresentation.Name & "_" & slideNum & ".jpg"
End If


ActivePresentation.Slides(slideNum).Export _
FileName:=imagePath & ActivePresentation.Name & "_" & slideNum & ".jpg", _
FilterName:="JPG"

End Sub

1 个答案:

答案 0 :(得分:0)

如果您在幻灯片放映期间引用了SlideIndex,则可以这样操作:

slideNum = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex

这是完整的代码,进行了一些细微的修改:

Sub SaveCurrentSlideAsJpg()
    Dim imagePath As String
    Dim slideNum As Integer
    Dim fullJpgName As String

    imagePath = "C:\JPG\"

    slideNum = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
    fullJpgName = imagePath & ActivePresentation.Name & "_" & slideNum & ".jpg"

    If Dir(fullJpgName) <> "" Then
        Kill fullJpgName
    End If

    ActivePresentation.Slides(slideNum).Export _
        FileName:=fullJpgName, FilterName:="JPG"
End Sub