+ Reply to Thread
Results 1 to 3 of 3

Renaming a button using a macro

  1. #1
    fullers
    Guest

    Renaming a button using a macro

    Hi,

    Hopefully an easy question to answer.

    I have written a macro that adds a button and renames it. Below is the code:

    ActiveSheet.Buttons.Add(2, 2, 100, 50).Select
    ActiveSheet.Shapes("Button 1").Select
    Selection.Characters.Text = "Print pages"

    This works fine when the new button added is actually called "Button 1".
    What I want to do is replace with "Button 1" with a more generic name so if
    the button added is actually called "Button 2" etc.. the macro will still
    work.

    Thanks in advance.

  2. #2
    Norman Jones
    Guest

    Re: Renaming a button using a macro

    Hi Fullers,

    Try:

    '=============>>
    Public Sub Tester031()
    Dim BTN As Button
    Set BTN = ActiveSheet.Buttons.Add(2, 2, 100, 50)
    BTN.Caption = "Print pages"

    End Sub
    '<<=============


    ---
    Regards,
    Norman



    "fullers" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > Hopefully an easy question to answer.
    >
    > I have written a macro that adds a button and renames it. Below is the
    > code:
    >
    > ActiveSheet.Buttons.Add(2, 2, 100, 50).Select
    > ActiveSheet.Shapes("Button 1").Select
    > Selection.Characters.Text = "Print pages"
    >
    > This works fine when the new button added is actually called "Button 1".
    > What I want to do is replace with "Button 1" with a more generic name so
    > if
    > the button added is actually called "Button 2" etc.. the macro will still
    > work.
    >
    > Thanks in advance.




  3. #3
    Xcelion
    Guest

    RE: Renaming a button using a macro

    Hi,

    Please use the index to access shape like

    ActiveSheet.Shapes(index) to aceess the shape object rather than giving the
    name

    Thanks
    Xcelion




    "fullers" wrote:

    > Hi,
    >
    > Hopefully an easy question to answer.
    >
    > I have written a macro that adds a button and renames it. Below is the code:
    >
    > ActiveSheet.Buttons.Add(2, 2, 100, 50).Select
    > ActiveSheet.Shapes("Button 1").Select
    > Selection.Characters.Text = "Print pages"
    >
    > This works fine when the new button added is actually called "Button 1".
    > What I want to do is replace with "Button 1" with a more generic name so if
    > the button added is actually called "Button 2" etc.. the macro will still
    > work.
    >
    > Thanks in advance.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1