Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for renaming worksheets Joe[_9_] New Users to Excel 4 January 19th 08 06:08 PM
Renaming a Macro Excel User Excel Programming 1 January 31st 06 07:07 PM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar[_15_] Excel Programming 1 May 26th 04 09:45 AM
renaming worksheet from within macro Mark w Excel Programming 2 May 17th 04 03:41 AM
Renaming FORM button Dr. Schwartz[_3_] Excel Programming 2 January 19th 04 02:06 PM


All times are GMT +1. The time now is 11:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"