Results 1 to 3 of 3

Thread: Changing button names - [resolved]

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    Changing button names - [resolved]

    Ok - new one for you guys and gals.

    I have a sheet with three Form Control buttons. Each button has a macro assigned to it. There is a Back, a Next and a Print button.

    I copy the sheet to a new workbook (see my previous answer to DaveBo's post for code example). Code works exceptionally well and moves the sheet to a new workbook. Now from here, I want to strip the sheet of the three Form Control Buttons.

    It is a very straightforward code approach to accomplish this.
    Essentially, something like, with sheets(1).Shapes("Button 2").Cut
    I name the shape by name since I have lots of other shapes on the sheet that must remain in place as they are graphics and are an integral part of my presentation.

    Problem is that Excel randomly renames my buttons for me while pasting. Button 38 can become Button 42. It is consistent providing I start with the same base number of buttons, but if I start another version of Excel, or open another workbook, then it increments its Button count to match, leaving my code dead in the water.

    I would like suggestions as to how to code to trap just my three buttons while leaving out the rest of my shapes. Something that would be irrelevant of the button number would be nice.
    Last edited by TheFIDDLER; Apr 27th, 2004 at 04:27 PM.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  2. #2
    New Member
    Join Date
    Apr 2004
    Posts
    12
    Here are a couple ways to identify the buttons. The first loop will work for buttons created from the Control Toolbox toolbar while the second loop will work for buttons created from the Forms toolbar.

    It sounds like the buttons that you have are from the Forms toolbar. However, I would suggest that you replace them with buttons from the Control Toolbox. Instead of assigning a macro to the button you would add code to the button's click event. These buttons can be identified as CommandButtons as opposed to a generic msoFormControl type.


    HTH




    VB Code:
    1. Dim o As OLEObject
    2.    
    3. For Each o In Sheet1.OLEObjects
    4.     If TypeName(o.Object) = "CommandButton" _
    5.      Then MsgBox o.Name, vbOKOnly, "Here's one!"
    6. Next o
    7.    
    8. Set o = Nothing
    9.    
    10. '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    11.    
    12. Dim s As Shape
    13.    
    14. For Each s In Sheet1.Shapes
    15.     If Left(s.Name, 7) = "Button " And s.Type = msoFormControl _
    16.      Then MsgBox s.Name, vbOKOnly, "Here's one!"
    17. Next s
    18.    
    19. Set s = Nothing

  3. #3

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    Thank you very much.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

Posting Permissions

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



Click Here to Expand Forum to Full Width