+ Reply to Thread
Results 1 to 8 of 8

Return the Name/Caption and Color of a Command Button

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2007
    Posts
    11

    Return the Name/Caption and Color of a Command Button

    I have developed code to build a dynamic calendar. One of the last things I need to do is return the name and color assigned to a command button on my worksheet. When I create the buttons the intention is the data on the button goes into the appropriate cell in the calendar and the color matches that of the text. However I cannot figure out how to return that information when I click on the button any suggestions please. I could type in the data again (as Ic an see it onthe button) but that is not efficent.

    Peter:
    Last edited by VBA Noob; 11-03-2007 at 05:21 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Like this?
    Private Sub CommandButton1_Click()
        With CommandButton1
            MsgBox "Caption: " & .Caption & vbLf _
            & "Name: " & .Name & vbLf _
            & "Color: " & .BackColor
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    09-08-2007
    Posts
    11

    Not Quite

    I build the buttons dynamically and as I build them I assign a routine to them. That routine does not know what the name/caption of the command button is. So your suggestion will not work but thank you for the suggestion. Is there a way of writing a sub routine using code?

    As I click the button I need to return the properties of that button I hope that does not sound stupid. If you would like me to post the code that builds the button please let me know.

    Thanks

    Peter

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Why go to the trouble of creating a command button in code, rather than creating a calender input in a cell, formatting as you wish, and pushing a button (or just double-clicking the cell) to move the text (and its formatting) to the calendar?

  5. #5
    Registered User
    Join Date
    09-08-2007
    Posts
    11
    Because what I am doing is prpearing a calendar that records locations. So When I am asked for the data I also specify the duration and it fills in the data andf colors for "X" days and this changes all the time.

    Regards

    Peter

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I guess my question is, what additional information can you convey with whatever formatting and attribution you can apply to a command button that you might not equally convey via alternative and simpler means?

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It seems over complicated to me, can you attach a small example workbook?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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