VBA Buttons to activate hyperlinks RRS feed

  • Question

  • I downloaded the following because I wanted to use buttons in protected Word documents to activate a hyperlink (buttons do not work in a protected word form).

    It works fine, except that I do not know where or how in this script to have the hyperlink activated when the button is pushed.  Currently, what the button does do is open a 'message box' telling me I have clicked the button.


    What (and where) do I add to this script to open a specific hyperlink?

    Sub Test()
        'Add a command button to a new document
        Dim doc As Word.Document
        Dim shp As Word.InlineShape
        Set doc = Documents.Add
        Set shp = doc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
        shp.OLEFormat.Object.Caption = "Click Here"
        'Add a procedure for the click event of the inlineshape
        '**Note: The click event resides in the This Document module
        Dim sCode As String
        sCode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & vbCrLf & _
                "   MsgBox ""You Clicked the CommandButton""" & vbCrLf & _
                "End Sub"
        doc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString sCode
    End Sub


    Thanks,  Ken

    Sunday, December 26, 2010 8:30 AM