Announcement

Collapse
No announcement yet.

Rename Command Button

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rename Command Button



    I'm having a problem with some of the command buttons in a dynamic spread sheet that I am creating. I add the command button to the page and it has the name "commandbutton1" I would like to rename it to something more meaningful. When I rename the button and then loop through the buttons on the page and try to match the name it doesn't work. I put in a message box to see what names it is pulling back and it for some reason keeps pulling back "commandbutton1" even after I updated the name property.

    Anyone have any ideas on what is causing this issue?

    Thanks
    Troy

  • #2
    Re: Renaming Command Button

    Troy

    How have you tried this?

    And how are you (in fact why are you) creating the buttons dynamically?

    ADDED BY ADMIN

    To name CommandButton ( ActiveX From Control Toolbox )

    Right click on the button and choose Properties and edit (Name).

    To name aButton ( NOT ActiveX From Forms Toolbar )

    Select the button and type a new name in the Name Box (left of the Formula Bar) and then Enter.
    Last edited by Dave Hawley; March 18th, 2008, 11:08.
    Boo!

    Comment


    • #3
      Re: Renaming Command Button

      Welcome to ozgrid

      Are you “re-naming” the Name property or perhaps the Caption property?

      Are these activeX buttons on the worksheet?
      Bill
      Tip: To avoid chasing code always use Option Explicit.

      Comment


      • #4
        Re: Renaming Command Button

        Sorry I miss spoke the spread sheet is being created to collect dynamic data. The pages have a preset layout with command buttons.

        I think it has something to do with the length of the name. Is there a char limit on the name of the buttons? I tried a shorter name and it changed the name.

        Thanks
        Troy
        Auto Merged Post Until 24 Hrs Passes;

        Yes I am renaming the name property not the caption.

        Not sure if they are activeX buttons. I inherited the spread sheet and I'm updating it. I know they are not marco buttons if that makes a difference and they have onclick properties.

        Thanks
        Troy
        Last edited by trichard0987; March 18th, 2008, 02:39. Reason: Auto Merged Doublepost

        Comment


        • #5
          Re: Renaming Command Button

          They must be activeX if the name is “Commandbutton1”. Buttons of the Forms menu are named “Button 1”.

          Will guess what. I did a test and the name change failed when I added character 129 (Starting with a one character name). Are your names longer than that? I can’t imagine why they would be.
          Bill
          Tip: To avoid chasing code always use Option Explicit.

          Comment


          • #6
            Re: Renaming Command Button

            Nope only 35 chars ExportMaterialTransferButton worked but ExportMaterialTransferReportButton did not. It didn't throw an error and it shows it renamed it but when I loop through the controls on the sheet the name hadn't changed.

            Comment


            • #7
              Re: Renaming Command Button

              I have no problem naming a n activex button on a sheet "ExportMaterialTransferReportButton".

              Can you please post a sample
              Bill
              Tip: To avoid chasing code always use Option Explicit.

              Comment


              • #8
                Re: Renaming Command Button

                I have a work book with 9 sheets and I want to have on sheet that will export all the data from the other sheets so I have a button on that first sheet that will export all sheets and when I put this code under the button click event and execute it the name of the button I changed on one of the other sheet is not getting saved and it displays the old button name.

                Not sure if that made sense but let me know.

                Code:
                Private Sub ExportEntireReportButton_Click()
                       Dim wsheet As Worksheet
                        
                        'Loop through all Worksheets
                        For Each wsheet In Worksheets
                        
                            'MsgBox (wsheet.Name)
                            
                            ' Select current sheet.
                            Sheets(wsheet.Name).Select
                            
                            Dim OleObj As OLEObject
                            
                            ' Loop through each object on the sheet.
                            For Each OleObj In wsheet.OLEObjects
                               '****************************************
                                MsgBox OleObj.Name ' This gets the name of the object
                               '****************************************
                
                            Next OleObj
                        Next wsheet
                End Sub

                Comment


                • #9
                  Re: Renaming Command Button

                  You have posted code that displays the name of the objects.

                  Were is the code that you attempt to change the name?? That’s what we need to see.
                  Bill
                  Tip: To avoid chasing code always use Option Explicit.

                  Comment


                  • #10
                    Re: Renaming Command Button

                    Troy

                    Bill's right - we don't need to see code that loops through and display button names.

                    And it also might be helpful if you actually clarified what you are doing in the first place.

                    I was pretty confused by your earlier post, but that's not unusual.

                    Why are you dynamically creating these buttons?

                    Why do you need to rename them?
                    Boo!

                    Comment


                    • #11
                      Re: Renaming Command Button

                      I'm not creating the buttons dynamically they are statically created on the page. There is not code for changing the buttons. I'm changing the name of the button on the sheet itself.

                      Ok I will try to explain it better.

                      I have a workbook that has 7 sheets. Each sheet is a report. Each report has a button to export the data on the sheet to a database. I'm adding a main sheet that will loop through each sheet and export the data, so the users doesn't have to go to each sheet individually and export the data.

                      What the above code does is loop through each sheet and then loop through the objects on that page. If the object matches one of the export buttons I export the data for that sheet and then move on the the next sheet.

                      My problem is lets say on sheet 3. I have a button that is called ExportSheet3ReportButton. When I create the button it is call commandbutton1 then I rename it to ExportSheet3ReportButton. When I got to the main page to export all the sheets I click the ExportAllSheets button and for debugging purposes I display the name of each object when it gets to the ExportSheet3ReportButton instead of showing the name ExportSheet3ReportButton it still shows commandbutton1 even though I changed the name on the sheet itself.

                      Does that make sense?

                      Thanks
                      Troy

                      Comment


                      • #12
                        Re: Renaming Command Button

                        Troy

                        Why are you even using buttons in the first place?

                        Am I missing something?

                        Looping through worksheet is pretty straightforward.
                        Boo!

                        Comment


                        • #13
                          Re: Renaming Command Button

                          That is how the spreadsheet was setup originally.

                          What's the other option?

                          Comment


                          • #14
                            Re: Renaming Command Button

                            Just use a button on your main sheet to start the procedure and use a reference in a cell on each sheet to be exported indicating if it is, in fact, ready to be exported.

                            Still haven't seen a sample workbook of your original problem. Last request
                            Bill
                            Tip: To avoid chasing code always use Option Explicit.

                            Comment


                            • #15


                              Re: Renaming Command Button

                              Sorry,

                              I cannot upload an example the spreadsheet is to large for the forum.


                              Thanks
                              Troy
                              Last edited by Dave Hawley; March 18th, 2008, 11:04.

                              Comment

                              Working...
                              X