vba超链接和形状创建

时间:2012-01-02 20:42:01

标签: vba powerpoint-vba

我有一个会创建一个形状的子程序,但是代码有两个问题:

  • 我必须指定在哪个幻灯片上创建此形状。如果我想同时在多个幻灯片上创建相同的形状,这是一个问题。我如何实现这一目标?如何用?
  • 替换activepresentation.slides(x)
  • 我希望该形状具有指向特定幻灯片的超链接。我的代码实现了什么问题?当我尝试将动作分配给我创建的形状时,它会给我一个错误。

Sub createshape()
    Dim oshp As Shape
    Dim osld As Slide

    'old code
    Set osld = ActivePresentation.Slides(1)
    Set oshp = osld.Shapes.AddShape(msoShapeRectangle, 485, 15, 104, 60)
     oshp.ActionSettings (ppMouseClick)
         .Action = ppActionHyperlink
         .Hyperlink.Address = SlideNumber
         .Hyperlink.SubAddress = 1 'this should take the hyperlink to slide 1 i hope.
End Sub

我想自动化这个功能,因为我会多次为许多幻灯片做同样的事情。

1 个答案:

答案 0 :(得分:1)

这样的事情会对当前幻灯片起作用。我测试了一个幻灯片2超链接,以确保代码工作(并且没有使用1作为默认值)

Sub CreateShape()
    Dim oShp As Shape
    Dim oSld As Slide
    Set oSld = ActivePresentation.Slides(ActiveWindow.Selection.SlideRange.SlideIndex)
    Set oShp = oSld.Shapes.AddShape(msoShapeRectangle, 485, 15, 104, 60)
    With oShp.ActionSettings(ppMouseClick)
        .Action = ppActionHyperlink
        '.Hyperlink.Address = SlideNumber
        .Hyperlink.SubAddress = 2
    End With
End Sub