【问题标题】:Run macro and hyperlink in one mouse click一键运行宏和超链接
【发布时间】:2018-02-25 02:47:07
【问题描述】:

我需要一个 PowerPoint 幻灯片中的按钮,当我单击它时,它将 1) 运行宏和 2) 超链接到同一演示文稿中的另一张幻灯片。

我只能看到一种方法来做一个或另一个,而不是同时做。

我的宏代码是:

Sub question1_real()
Dim oSh As Shape
   Dim oSl As Slide
   Dim lScore As Long

   ' By doing it this way it's easy to change to a different slide if you
   ' need to later for some reason:
   Set oSl = ActivePresentation.Slides(18)

   ' Change this if your shape is named something else:
   Set oSh = oSl.Shapes("TextBox 2")

   With oSh
      ' Make sure it's not blank to start with:
      If Len(.TextFrame.TextRange.Text) = 0 Then
          .TextFrame.TextRange.Text = "1"
      End If
      lScore = CLng(.TextFrame.TextRange.Text)
      lScore = lScore + 1
      .TextFrame.TextRange.Text = CStr(lScore)
   End With
End Sub

我的 VBA 技能为零。上面的代码是从某人那里借来的。我使用 PowerPoint 中的“插入操作”选项使其工作。

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

    假设您为形状设置了运行宏操作设置并选择了您在上面发布的子例程,您可以将此函数添加到 VBA 项目中:

    Sub JumpTo(lSlideIndex As Long) SlideShowWindows(1).View.GoToSlide (lSlideIndex) 结束子

    然后无论你想跳到另一张幻灯片,这样称呼它:

    Call JumpTo(42) ' or whatever slide you want to jump to
    

    或者只是

    JumpTo 42
    

    如果您需要在演示文稿中多次使用它,那么在函数中使用它会更方便。如果严格来说是一次性的,您可以将其粘贴到现有代码中:

    SlideShowWindows(1).View.GoToSlide (42)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多