Consulting

Results 1 to 9 of 9

Thread: Make a command button self-distruct

  1. #1
    VBAX Regular
    Joined
    May 2017
    Location
    Dunedin, Otago
    Posts
    11
    Location

    Make a command button self-distruct

    Excuse my ignorance, but how can I make a command button self destruct?
    I'm making an excel 'zerg rush' style game thingy.

    Thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Like this?
    Private Sub CommandButton1_Click()
    MsgBox "About to self destruct"
    Me.Shapes("CommandButton1").Delete
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    May 2017
    Location
    Dunedin, Otago
    Posts
    11
    Location
    Perfect! Thanks!

  4. #4
    VBAX Regular
    Joined
    May 2017
    Location
    Dunedin, Otago
    Posts
    11
    Location
    This is probably quite an unusual question, but how could I make a command button self destruct if another command button lands on it? I cannot record this as I do not know which command button will land on what command button...
    Thanks

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Buttons don't land.

    What are you trying to do.

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by mikerickson View Post
    Buttons don't land.
    But if they never land, how do they get on the sheet?

    (Sorry Mike, I just couldn't resist)

  7. #7
    Please be aware that removing or adding an ActiveX control on a worksheet resets the code in the file in question.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Rather than destroying controls, it is probably better to make them not visible.

  9. #9
    VBAX Regular
    Joined
    May 2017
    Location
    Dunedin, Otago
    Posts
    11
    Location
    Ok. I was trying to make a 'zerg rush' game where little squares (command buttons) jump round and when one lands on your square your square 'dies'.

Tags for this Thread

Posting Permissions

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