+ Reply to Thread
Results 1 to 4 of 4

How can I programatically change the caption on a button?

  1. #1
    June Macleod
    Guest

    How can I programatically change the caption on a button?

    Microsoft Excel 2003


    I have created a button on a spreadsheet using the following code

    ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
    Link:=False _
    , DisplayAsIcon:=False, Left:=147, Top:=27.75, Width:=145.5,
    Height:= _
    33).Select
    ActiveSheet.Shapes("CommandButton1").Name = "cmdButton"

    but when I try and set a caption for the button using:
    ActiveSheet.Shapes("CommandButton1").caption = "Hello World" it tells me
    that the
    "Object doesn't support this object or method"

    When I try and record a macro to change the caption I end up with:
    ActiveSheet.Shapes("CommandButton1").Select
    Selection.Verb Verb:=xlPrimary

    which frankly, I don't understand.

    Can anyone help me here and tell me how to apply a caption to my button.


    Many thanks


    June



  2. #2
    Ron de Bruin
    Guest

    Re: How can I programatically change the caption on a button?

    Hi June

    Try this

    ActiveSheet.OLEObjects("cmdButton").Object.Caption = "Hi there"

    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "June Macleod" <junemacleod@btconnect.com> wrote in message news:Cs2dnfpVbPfCLeTZRVnyrg@bt.com...
    > Microsoft Excel 2003
    >
    >
    > I have created a button on a spreadsheet using the following code
    >
    > ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
    > Link:=False _
    > , DisplayAsIcon:=False, Left:=147, Top:=27.75, Width:=145.5,
    > Height:= _
    > 33).Select
    > ActiveSheet.Shapes("CommandButton1").Name = "cmdButton"
    >
    > but when I try and set a caption for the button using:
    > ActiveSheet.Shapes("CommandButton1").caption = "Hello World" it tells me
    > that the
    > "Object doesn't support this object or method"
    >
    > When I try and record a macro to change the caption I end up with:
    > ActiveSheet.Shapes("CommandButton1").Select
    > Selection.Verb Verb:=xlPrimary
    >
    > which frankly, I don't understand.
    >
    > Can anyone help me here and tell me how to apply a caption to my button.
    >
    >
    > Many thanks
    >
    >
    > June
    >
    >




  3. #3
    Ron de Bruin
    Guest

    Re: How can I programatically change the caption on a button?

    In one step do it like this

    Dim Ws As Worksheet
    Dim Btn As OLEObject

    With ActiveSheet
    Set Btn = .OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
    Left:=.Range("C3").Left, Top:=.Range("C3").Top, _
    Width:=100, Height:=30)
    End With
    Btn.Object.Caption = "Print workbook"
    Btn.Name = "YourPrintButton"


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "June Macleod" <junemacleod@btconnect.com> wrote in message news:Cs2dnfpVbPfCLeTZRVnyrg@bt.com...
    > Microsoft Excel 2003
    >
    >
    > I have created a button on a spreadsheet using the following code
    >
    > ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
    > Link:=False _
    > , DisplayAsIcon:=False, Left:=147, Top:=27.75, Width:=145.5,
    > Height:= _
    > 33).Select
    > ActiveSheet.Shapes("CommandButton1").Name = "cmdButton"
    >
    > but when I try and set a caption for the button using:
    > ActiveSheet.Shapes("CommandButton1").caption = "Hello World" it tells me
    > that the
    > "Object doesn't support this object or method"
    >
    > When I try and record a macro to change the caption I end up with:
    > ActiveSheet.Shapes("CommandButton1").Select
    > Selection.Verb Verb:=xlPrimary
    >
    > which frankly, I don't understand.
    >
    > Can anyone help me here and tell me how to apply a caption to my button.
    >
    >
    > Many thanks
    >
    >
    > June
    >
    >




  4. #4
    Don Wiss
    Guest

    Re: How can I programatically change the caption on a button?

    On Sun, 28 May 2006, June Macleod <junemacleod@btconnect.com> wrote:

    >Microsoft Excel 2003
    >
    >I have created a button on a spreadsheet using the following code
    >
    > ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
    > , DisplayAsIcon:=False, Left:=147, Top:=27.75, Width:=145.5, Height:= _
    > 33).Select


    Why are you creating a button from the Control Toolbox? Why not from the
    Forms toolbox?

    > ActiveSheet.Shapes("CommandButton1").Name = "cmdButton"
    >
    >but when I try and set a caption for the button using:
    >ActiveSheet.Shapes("CommandButton1").caption = "Hello World" it tells me
    >that the
    >"Object doesn't support this object or method"


    That would work fine if you created a Forms button.

    Don <www.donwiss.com> (e-mail link at home page bottom).

+ 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