+ Reply to Thread
Results 1 to 7 of 7

How to get the button object using its caption ?

Hybrid View

kvramana82 How to get the button object... 02-08-2013, 08:02 AM
OllieB Re: How to get the button... 02-08-2013, 08:12 AM
kvramana82 Re: How to get the button... 02-08-2013, 08:23 AM
jraj1106 Re: How to get the button... 02-08-2013, 08:19 AM
kvramana82 Re: How to get the button... 02-08-2013, 09:09 AM
JosephP Re: How to get the button... 02-08-2013, 09:12 AM
OllieB Re: How to get the button... 02-08-2013, 09:29 AM
  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    21

    How to get the button object using its caption ?

    Hi All,

    I have a button in Sheet1 with caption "Go To Master". Now i want to find this button with its caption (Not with Button Name).

    As per my requirement i am copying some columns from sheet1 to different sheets and these columns include this button.

    In some cases i don't want to have this button. So wherever it is applicable i want to find this button with its caption and delete it.

    Thanks & Regards,

    Ramana

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: How to get the button object using its caption ?

    Ramana, you will have to loop through the Shapes or OLEObjects collection for the worksheet object (depending on whether you have a Forms or ActiveX type of button), and identify the correct button by looking at the caption displayed
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    12-15-2010
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: How to get the button object using its caption ?

    Hi OllieB,

    Thanks for the quick response..
    Can you please let me know the exact code to loop through shapes. its a form control in a sheet not ActiveX control.

    Activesheet.shapes(i).name = "?"
    As far as i know its a button name, I cannot give caption name here. Its impposible for me to find the object name as i keep pasting the columns.
    I only way i can see is using caption name i have to find the button name.

    I am just getting an idea if i try using ActiveX control then is there a way to find the object using caption.

    Can you please suggest a way?

    Thanks & Regards,

    Ramana

  4. #4
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: How to get the button object using its caption ?

    Hi Ramana.

    I m not sure if this is what you want but just check:

    Sub COPYBUTTON()
        If Sheet1.CommandButton1.Caption = "Go To Master" Then
            ActiveSheet.Shapes("CommandButton1").Select
            Selection.Delete
        End If
    End Sub
    Click *, if my suggestion helps you. Have a good day!!

  5. #5
    Registered User
    Join Date
    12-15-2010
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: How to get the button object using its caption ?

    hi jraj1106,

    Thanks for the reply. This is not exactly i am looking. I think your code is for ActiveX control.
    To solve my issue I believe that i should replace form control button with ActiveX control button.

    Thanks,
    Ramana

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to get the button object using its caption ?

    for instance
    dim btn as button
    for each btn in activesheet.buttons
    if btn.caption = "Go To Master" Then btn.delete
    next btn
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: How to get the button object using its caption ?

    Something like

         Dim objShape As Shape
         For Each objShape In ActiveSheet.Shapes
              If objShape.TextFrame.Characters.Text = "Go To Master" Then
                   objShape.Delete
              End If
         Next objShape

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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