我正在开发一个交互式Powerpoint演示文稿,用户可以点击照片的缩略图,几乎可以全屏查看。我在使用.Shapes和.Slides方法时遇到困难。
我想在演示文稿的一张幻灯片上显示几个较小的图像。如果用户想要查看它非常大,他们只需要点击图像即可。然后,我希望图像显示在它自己新生成的幻灯片上,尽可能大,因为它可以放在幻灯片上。当他们点击较大的图像时,它们将被带回他们正在查看的较小的图像幻灯片。通过为节目中的每个小图像制作单独的全尺寸图像幻灯片,并在单击小图像时简单地调用大幻灯片编号,可以很容易地实现这一点。然而,这是耗时的,并使演示文稿远远超过它所需要的。如果用户从不点击查看放大的图像,则具有大图像的页面占用空间。当我点击图片时,我选择执行vba代码:
码:
Sub ViewFullSize()
Dim pptNewSlide As Slide
' Dim objCurrentSlideIndex As Integer
' objCurrentSlideIndex = ActiveWindow.Selection.SlideRange.SlideIndex
With ActivePresentation
.Slides(2).Shapes("Picture 7").Copy
.Slides(4).Shapes.Paste
End With
Set pptNewSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutCustom)
ActivePresentation.SlideShowWindow.view.Last
End Sub
此代码执行并执行所需的操作。我的问题是,我需要幻灯片编号和形状编号作为变量。我不想为100张可以点击的照片重写这段代码。我试图让当前的幻灯片变成这样的变量:
Dim objCurrentSlideIndex As Integer
objCurrentSlideIndex = ActiveWindow.Selection.SlideRange.SlideIndex
With ActivePresentation
.Slides(objCurrentSlideIndex).Shapes("Picture 7").Copy
.Slides(4).Shapes.Paste`
End With
我尝试.Slides(objCurrentSlideIndex)
的变量导致整个子程序不执行,但不会使幻灯片崩溃。我已经使用了Set
和一些其他语法,并且无法使用变量而不是普通数字。有没有办法做到这一点? .Slides()
和.Shapes()
方法甚至可以使用变量吗?我已经阅读了几个Microsoft和PPTools页面,但是找不到使用变量的例子。
Sub ViewFullSize(objCurrentShape As Shape) ' Place shape clicked on into variable.
Dim pptNewSlide As Slide
Dim objCurrentSlideNum As Integer
Dim objLastSlideNum As Integer
' Place current slide number into a variable.
objCurrentSlideNum = ActivePresentation.SlideShowWindow.view.CurrentShowPosition
' Send shape to clipboard for later pasting.
ActivePresentation.Slides(objCurrentSlideNum).Shapes(objCurrentShape.Name).Copy
' Place new blank slide at the end of the presentation.
Set pptNewSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutCustom)
' Make the new slide the active slide.
ActivePresentation.SlideShowWindow.view.Last
' Place the new slide number into a variable.
objLastSlideNum = ActivePresentation.SlideShowWindow.view.CurrentShowPosition
' Paste the shape image from the clipboard onto the new slide.
ActivePresentation.Slides(objLastSlideNum).Shapes.Paste
End Sub
我偶然发现了一段代码,显示单击一个形状时,它可以将其标识符直接传递给子程序并分配给变量。在我的情况下(objCurrentShape As Shape)
。这可以与.Shapes()
方法一起使用,我曾经称之为复制.Shapes(objCurrentShape.Name).Copy
的形状。
.Slides()
方法更容易分配给变量(或者我相信),因为它不依赖于点击的形状。它只是活动的幻灯片编号,是通过.View.CurrentShowPosition
函数获得的。
此代码现在可以分配给幻灯片上的任意数量的形状,并将复制并通过该形状到演示文稿末尾新创建的空白幻灯片,以便进一步操作。
完全正常的代码!
对于任何感兴趣的人来说,这是我在Powerpoint 2017中工作的完整(可能没有收集),完全可操作的代码。
这被设计为幻灯片中的图片指定为宏动作。当页面上有多个较小尺寸的图像时,可以为每个图像分配一个宏,该宏将在其自己的幻灯片上全屏显示图像,然后将用户直接发送回包含较小图像的屏幕。这有点像全屏缩放功能。
它记录在案,并且我可以记录,以允许任何人跟随allong与每一步发生的事情。如果我说错了,欢迎编辑正确的措辞和术语。
这不是我的机器或路径或类似的东西。您只需复制并粘贴到powerpoint中的模块中,然后开始将新宏指定给演示文稿中的任何图像。
Sub ViewFullSize(objCurrentShape As Shape) ' Place shape clicked-on into variable.
' Credit Shyam Pillai @ http://www.skphub.com/ppt00040.htm#2 for the method of
' bringing the shape into the macro as a variable allowing easier manipulation.
Dim pptNewSlide As Slide
Dim objCurrentSlideNum As Integer
Dim objLastSlideNum As Integer
Dim objLargeView As Shape
' Place current slide number into a variable.
objCurrentSlideNum = ActivePresentation.SlideShowWindow.view.CurrentShowPosition
' Copy shape to clipboard for later pasting.
ActivePresentation.Slides(objCurrentSlideNum).Shapes(objCurrentShape.Name).Copy
' Place new blank slide at the end of the presentation.
Set pptNewSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
' Make the new slide the active slide.
ActivePresentation.SlideShowWindow.view.Last
' Place the new slide number into a variable.
objLastSlideNum = ActivePresentation.SlideShowWindow.view.CurrentShowPosition
' Paste the shape image from the clipboard onto the new slide.
ActivePresentation.Slides(objLastSlideNum).Shapes.Paste
' Put pasted image into a variable.
Set objLargeView = ActivePresentation.Slides(objLastSlideNum).Shapes(1)
' Full credit for this next section of the code goes to PPTools & David Marcovitz
' @ http://www.pptfaq.com/FAQ00352_Batch_Insert_a_folder_full_of_pictures-_one_per_slide.htm
' Thanks for the hard work!
' Manipulate the image using the variable.
With objLargeView
' Set mouse-click action on image to return user back to the slide they came from.
.ActionSettings(ppMouseClick).Action = ppActionLastSlideViewed
' Reposition the image for proper resizing
.Left = 0
.Top = 0
.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
' Resize the image to full screen while maintaining aspect ratio.
' This is wide screen mode. If you are working with the more
' narrow mode, simply change the 9 to a 3 and the 16 to a 4
' to keep the correct aspect ratio.
If 9 * .Width > 16 * .Height Then
.Width = ActivePresentation.PageSetup.SlideWidth
.Top = 0.5 * (ActivePresentation.PageSetup.SlideHeight - .Height)
Else
.Height = ActivePresentation.PageSetup.SlideHeight
.Left = 0.5 * (ActivePresentation.PageSetup.SlideWidth - .Width)
End If
End With
' From here, the slideshow is now showing the originally clicked-on image
' full screen on its own page waiting for the user to click on it to return
' to the rest of the show. If the slideshow isn't set to kiosk mode, then
' there is the possibility of the user clicking somewhere on the screen out
' of the picture area and it would end the slideshow.
End Sub