Consulting

Results 1 to 4 of 4

Thread: Change color and text of an Autoshape

  1. #1
    VBAX Regular pegbol's Avatar
    Joined
    Feb 2005
    Posts
    45
    Location

    Change color and text of an Autoshape

    .
    .

    Hello,

    How can change the text and color of an autoshape when click and run a macro ?.

    Example:
    When clik button (Letter A) insert A in cell B3, and change the color and text of the same button to color green and text (Letter B).
    Then, the next time when click button (Letter B) insert B in cell B3, and change the color and text of the button to color red and text (Letter A).

    All with the same button.



    I enclose a file with my example.

    Thanks in advance for your kind help.

    best regards,
    Pedro
    .
    .

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi pegbol,

    Try this (you can also assign the macro to the autoshape so it changes when you click on it)

    Sub ChangeIt()
    ActiveSheet.Shapes("AutoShape 1").Select
    With Selection
    If .ShapeRange.Fill.ForeColor.SchemeColor = 57 Then
    GoTo LetterA
    Else
    GoTo LetterB
    End If
    LetterA:
    .ShapeRange.Fill.ForeColor.SchemeColor = 2
    .Characters.Text = "LETTER" & Chr(10) & "A"
    [B3] = "B"
    Exit Sub
    LetterB:
    .ShapeRange.Fill.ForeColor.SchemeColor = 57
    .Characters.Text = "LETTER" & Chr(10) & "B"
    [B3] = "A"
    End With
    End Sub

    HTH,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by pegbol
    .How can change the text and color of an autoshape when click and run a macro ?
    Hi Pedro,

    Replace your macro with this

    Sub letter()
    Dim sNext As String
        Application.ScreenUpdating = False
        ActiveSheet.Shapes("Autoshape 1").Select
        With Selection
            With .ShapeRange.Fill.ForeColor
                If .SchemeColor = 17 Then
                    Range("B3").FormulaR1C1 = "B"
                    .SchemeColor = 10
                    sNext = "A"
                Else
                    Range("B3").FormulaR1C1 = "A"
                    .SchemeColor = 17
                    sNext = "B"
                End If
            End With
            With .Characters(8, 1)
                .Text = sNext
                With .Font
                    .Name = "Arial"
                    .FontStyle = "Bold"
                    .Size = 24
                End With
            End With
        End With
        ActiveCell.Select
        Application.ScreenUpdating = True
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular pegbol's Avatar
    Joined
    Feb 2005
    Posts
    45
    Location
    .
    .
    Thanks you so much johnske and xld!!!!!



    best and kind regards,
    Pedro
    .
    .

Posting Permissions

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