+ Reply to Thread
Results 1 to 4 of 4

changing text of a button

Hybrid View

  1. #1
    Registered User
    Join Date
    07-21-2010
    Location
    quezon
    MS-Off Ver
    Excel 2007/2010
    Posts
    27

    changing text of a button

    Hi, how can I automatically change the text property of a shape?

    Here's the scenario,
    I have a rectangle that functions as a button. When the button is clicked, the text will be transferred from a variable.

    I don't know how to do this since the macros is not really a property of the object. In VB, the code is
    btn1.text = variable
    how do i do this in VBA?
    Last edited by LAazsx; 07-29-2010 at 11:18 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,535

    Re: changing text of a button

    So you're saying - you have a Macro assigned to the Shape which when run should modify the caption on the Shape itself ?

    If so, perhaps you want something like:

    Sub Rectangle1_Click()
        Dim strVar As String
        strVar = "Caption"
        ActiveSheet.Shapes("Rectangle 1").Select
        Selection.Characters.Text = strVar
    End Sub
    where Rectangle1_Click is the Macro assigned to the Shape itself.

  3. #3
    Registered User
    Join Date
    07-21-2010
    Location
    quezon
    MS-Off Ver
    Excel 2007/2010
    Posts
    27

    Re: changing text of a button

    Thanks. Uhm... How do i actually name the object?

  4. #4
    Registered User
    Join Date
    07-21-2010
    Location
    quezon
    MS-Off Ver
    Excel 2007/2010
    Posts
    27

    Re: changing text of a button

    Oh nevermind. found it thanks :D

    Edit: uhm can't get it to work properly. When I run the triggering button, all functions assigned except this text change function works. but when i try to run from the code window, the code works properly. the triggering button is on another sheet. this is my code

    Worksheets("Main").Shapes("Item 1").Select
    Selection.Characters.Text = Worksheets("Raw Materials").Range("H7").Value
    Last edited by LAazsx; 07-29-2010 at 11:20 AM.

+ 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