vba hyperlinks and shape creation

若如初见. 提交于 2019-12-11 00:28:49

问题


I have a subroutine that will create a shape, but I have two problems with the code:

  • I must specify on which slide this shape will be created. This is a problem if I want to create the same shape on multiple slides simultaneously. How do I achieve that? what do I replace activepresentation.slides(x) with?
  • I want the shape to have a hyperlink to a specific slide. What is wrong with my code to achieve that? It gives me an error when I try to assign an action to the shape I have created.

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

I want to automate this function because I will be doing this same thing for many many slides multiple times.


回答1:


Something like this will act on the current slide. I tested for a slide 2 hyperlink to esnure that the code worked (and didn't use 1 as default)

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


来源:https://stackoverflow.com/questions/8705136/vba-hyperlinks-and-shape-creation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!