Consulting

Results 1 to 2 of 2

Thread: Changing several button properties only for the buttons in a list

  1. #1
    VBAX Regular
    Joined
    Sep 2012
    Posts
    8
    Location

    Changing several button properties only for the buttons in a list

    Hey guys,

    I'm having some problem with a simple routine.

    If had a command button and I wanted to change it's caption I'd use:
    [vba]
    CommandButton1.Caption = "Something"
    [/vba]

    So if I wanted to change the Caption from all of the Button names from a list (like the code below which doesn't work) what would I have to do to make the CurrentCommandButton a CommandButton variable for the property Caption?
    [vba]
    For Each CurrentCommandButton In Range("SomeRange") 'SomeRange = A1:A200
    CurrentCommandButton.Caption = "Something"
    Next CurrentCode
    [/vba]

    So my goal is to change all of the captions from a list of Button Names.

    Thanks in advance.
    Last edited by blukrr; 09-05-2012 at 07:59 AM.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [vba]Sub NewCommandButtonCaptions()
    Dim cell As Range, i As Long
    With Worksheets("Sheet1")
    For Each cell In .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
    i = i + 1
    .OLEObjects(cell.Value2).Object.Caption = "Btn" & i
    Next cell
    End With
    End Sub[/vba]

Posting Permissions

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