Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete command button

Give that commandbutton a nice unique name (I used CMDOneTime.)

Then put this in your Auto_Open routine:

Option Explicit
Sub auto_open()

Dim wks As Worksheet
On Error Resume Next
For Each wks In ThisWorkbook.Worksheets
wks.OLEObjects("CMDOneTime").Delete
Next wks
On Error Resume Next

End Sub

You could use something like this to check for the commandbutton's existance
first:

Option Explicit
Sub auto_open()
Dim wks As Worksheet
Dim OLEObj As OLEObject

For Each wks In ThisWorkbook.Worksheets
Set OLEObj = Nothing
On Error Resume Next
Set OLEObj = wks.OLEObjects("CMDOneTime")
On Error GoTo 0

If OLEObj Is Nothing Then
'not there, do nothing
Else
OLEObj.Delete
End If
Next wks

End Sub

But if you're gonna use "on error resume next", why bother with the extra check
first?



DocBrown wrote:

I have a template which has a command button on a sheet. What I want to do is
when a user creates a NEW workbook from the template, I want the button to
exist. Then the next time they open the workbook, I want the button to be
deleted from the template sheet and any copies they've made of the sheet.

The sticky part is once the button is deleted, the next time the the file is
opened again, the control is gone so I get a runtime error because the
control doesn't exist. How can I check if the control exists before I try to
delete it.

Or is it just best to do the On Error Resume Next thing?

Thanks,
John


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete command button ? SpookiePower Excel Programming 3 January 23rd 06 02:46 PM
Delete a command button via VBA Brian K. Sheperd Excel Programming 2 June 8th 05 03:57 PM
Delete with command button? John[_100_] Excel Programming 3 March 17th 05 01:38 PM
Delete command button gavmer[_96_] Excel Programming 0 October 19th 04 12:56 AM
Delete command button BrianB Excel Programming 0 October 18th 04 10:28 AM


All times are GMT +1. The time now is 03:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"