Re: remove button

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



See my other post in this thread... it seems something is wrong with what I told you about naming the button.

Rick


"leungkong" <leungkong@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:4EEB3D0D-11A0-4008-AA46-CBF22D966F4D@xxxxxxxxxxxxxxxx
Thanks Rick. You not only help me to solve this problem but also help me to
open a door for how to handle with statement.
Best Regards
Kong

"Rick Rothstein (MVP - VB)" wrote:

You can just name it right after the With Selection statement...

Worksheets("MIRO").Buttons.Add(240, 15, 80, 16).Select
With Selection
.Name = "NewButtonName"
.OnAction = "break"
.Characters.Text = "Break"
With .Characters(Start:=1, Length:=8).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.ColorIndex = xlAutomatic
End With
End With

I posted the whole routine because I wanted to show you another way to
handle your With statements. Instead of ending the first With statement in
order to start your next one, which simply a property of the object you had
in your first With statement, you can just nest the continued With statement
instead. Notice the dot in front of the Characters(...) property call....
that just tells the second With statement to reference the first With
statement's object while inside the second With statement. When the second
(nested) With statement ends, the first With statement is back in
"control"... meaning and dotted properties you place after the inner With
statement's End With will reference the first With statement's object (in
this case, Selection). Once you get the hang of this, I think you will find
this a more convenient way to handle With statements.

Now, as for deleting the button (which I named NewButtonName in my above
example), just execute this code...

Worksheets("MIRO").Buttons("NewButtonName").Delete

substituting the name you give to the button when you create it.

Rick


"leungkong" <leungkong@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1CC0CE50-0117-405C-8CCD-8D72FA1C21B9@xxxxxxxxxxxxxxxx
>I have used below code to add a button when workbook open.
> I want to remove it when work close.
> But the button name is "Button 1".
> How can I change the name when I create the button? Thanks.
>
> Worksheets("MIRO").Buttons.Add(240, 15, 80, 16).Select
> With Selection
> .OnAction = "break"
> .Characters.Text = "Break"
> End With
> With Selection.Characters(Start:=1, Length:=8).Font
> .Name = "Arial"
> .FontStyle = "Regular"
> .Size = 10
> .ColorIndex = xlAutomatic
> End With
>



.



Relevant Pages

  • Re: remove button
    ... there is nothing wrong with what I told you about naming the button... ... With Selection ... you can just nest the continued With statement ... statement's End With will reference the first With statement's object (in ...
    (microsoft.public.excel.programming)
  • Re: Error 462 - Remote server machine does not exist or is unavail
    ... "Tony Jollans" wrote: ... Dim wdDoc As Word.Document ... reference that really shouldn't exist. ... Every Window in Word has a Selection, ...
    (microsoft.public.word.vba.general)
  • Re: Shapes at Runtime?
    ... label to any shape by clicking a shape and clicking ... execution enters the event handler. ... a function call that returns a reference _to_ the object. ... I'll name the field Selection and it will be of type TShape. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Mr. McGinn and "Eight" for starts.
    ... > statement I made that you think requires a reference. ... >>> selection it's not because they have any specific dispute it's ... > excuse list, everytime you use an excuse for not providing a ...
    (sci.anthropology.paleo)
  • Re: given names
    ... names and naming ... area cultures, but I'd be interested to hear if you come across ... Here's a selection relating to early modern European and American ... 'Tacit rules and hidden structures: naming practices ...
    (sci.lang)