Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Delete Insert Worksheet on Open/Reset on Close

New at VB. Need to delete Insert Worksheet from file menu at open and reset
at close. I got this code from MS site. Doesn't reset at close unless I hit
the F5 key.
Sub menuItem_Delete()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("Insert")
myCmd.Controls("Worksheet").Delete
End Sub
Sub MenuBar_Restore()
CommandBars("Insert").Reset
End Sub
Any help will be appreciated much.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Delete Insert Worksheet on Open/Reset on Close

First, I wouldn't use Reset - what if the user has other customizations?

I think you want to make the control not visible

Private Sub workbook_Open()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("Insert")
myCmd.Controls("Worksheet").Visible = False
End Sub

Private sub workbook_BeforeClose()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("Insert")
myCmd.Controls("Worksheet").Visible = True
End sub

this code would need to be in the ThisWorkbook module.

For information on Events, see Chip Pearson's site

http://www.cpearson.com/excel/events.htm

all that said, it might be better just to protect the structure of your
workbook (Tools=Protect=Protect Workbook)

that would disallow the insertion or deletion of worksheets.

--
Regards,
Tom Ogilvy






"Jane" wrote:

New at VB. Need to delete Insert Worksheet from file menu at open and reset
at close. I got this code from MS site. Doesn't reset at close unless I hit
the F5 key.
Sub menuItem_Delete()
Dim myCmd As Object
Set myCmd = CommandBars("Worksheet menu bar").Controls("Insert")
myCmd.Controls("Worksheet").Delete
End Sub
Sub MenuBar_Restore()
CommandBars("Insert").Reset
End Sub
Any help will be appreciated much.

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
Unable to delete or insert a worksheet. dmarten Excel Discussion (Misc queries) 2 October 31st 06 05:03 PM
How do I close excell worksheet without closing others still open John Excel Worksheet Functions 2 July 20th 06 06:17 PM
How can I use open/close Grouped cells in a Protected Worksheet? Andy Bowshell Excel Discussion (Misc queries) 2 January 16th 06 02:38 PM
Delete/Close Excel file that is kept OPEN Jafer New Users to Excel 0 April 15th 05 05:34 AM
Loop thru files in DIR, delete worksheets & reset worksheet Name property?? Mike Taylor Excel Programming 1 October 24th 03 04:14 AM


All times are GMT +1. The time now is 12:28 AM.

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"