Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jun 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adding custom buttons to worksheet (EXCEL 2000)

    Hello all,

    I am fairly new to visual basic. I managed to add buttons. But I am not sure how to run a macro on VB.

    I wanted each button to open a different sheet.

    Please see attachment

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: adding custom buttons to worksheet (EXCEL 2000)

    Something like this:
    <pre>Sub addbutton()
    Dim oButton As Object
    Set oButton = ActiveSheet.Buttons.Add(Left:=0, Top:=0, Width:=100, Height:=30)
    oButton.Caption = "Remove me!"
    oButton.OnAction = "Removebutton"
    Set oButton = Nothing
    End Sub

    Sub Removebutton()
    ActiveSheet.Buttons(Application.Caller).Delete
    End Sub
    </pre>

    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: adding custom buttons to worksheet (EXCEL 2000)

    I overlooked your attachment.

    The buttons you added are "control toolbox" buttons (my example adds a button from the forms toolbar).

    On de control toolbox, click the first icon so it appears depressed.
    Now click the second icon to expose the properties window.
    The title of the button is called the Caption. Change it in the properties window.
    After changing that for both buttons, double click one of them. This opens the Visual Basic editor with a piece of code already filled in:

    Private Sub Commandbutton1_Click()
    End Sub

    In between these two line type:

    Worksheets("Sheet2").Activate

    so you get:

    Private Sub Commandbutton1_Click()
    Worksheets("Sheet2").Activate
    End Sub

    Repeat this for the other button. Change the name of the sheet in the code above to fit your need.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •