Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default prevent a user from adding any sheet in a workbook

I have an excel workbook in which i don't want the user to add any
sheets.
I tried following code to delete the sheet every time a new sheet is
inserted.
However, Microsoft generates a message and user has to select Delete
key every time
and if the user presses cancel then a sheet is inserted.
How can i automatically make the Delete selection so that user cannot
insert aany sheets.

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Sh.Delete
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default prevent a user from adding any sheet in a workbook

Option Explicit
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Application.DisplayAlerts = False
Sh.Delete
Application.DisplayAlerts = True
End Sub


But you may want to just protect the workbook's structure.
Tools|Protection|protect workbook
is where you'd find it in xl2003 menus.

It prohibits the user from adding/deleting/changing the order/renaming of the
sheets.

This password (like most passwords) are easily cracked.

On the other hand, the code can be bypassed by disallowing macros to run -- or
just disabling events.

So nothing is really foolproof.



Subodh wrote:

I have an excel workbook in which i don't want the user to add any
sheets.
I tried following code to delete the sheet every time a new sheet is
inserted.
However, Microsoft generates a message and user has to select Delete
key every time
and if the user presses cancel then a sheet is inserted.
How can i automatically make the Delete selection so that user cannot
insert aany sheets.

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Sh.Delete
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default prevent a user from adding any sheet in a workbook

On Apr 6, 8:14*pm, Dave Peterson wrote:
Option Explicit
Private Sub Workbook_NewSheet(ByVal Sh As Object)
* * Application.DisplayAlerts = False
* * Sh.Delete
* * Application.DisplayAlerts = True
End Sub

But you may want to just protect the workbook's structure.
Tools|Protection|protect workbook
is where you'd find it in xl2003 menus.

It prohibits the user from adding/deleting/changing the order/renaming of the
sheets.

This password (like most passwords) are easily cracked.

On the other hand, the code can be bypassed by disallowing macros to run -- or
just disabling events.

So nothing is really foolproof.

Subodh wrote:

I have an excel workbook in which i don't want the user to add any
sheets.
I tried following code to delete the sheet every time a new sheet is
inserted.
However, Microsoft generates a message and user has to select Delete
key every time
and if the user presses cancel then a sheet is inserted.
How can i automatically make the Delete selection so that user cannot
insert *aany sheets.


Private Sub Workbook_NewSheet(ByVal Sh As Object)
Sh.Delete
End Sub


--

Dave Peterson


Thanks. It worked fine.
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
Macro to prevent adding sheet in a workbook. [email protected] Excel Programming 6 August 15th 06 03:49 AM
Prevent user from saving workbook keithl816 Excel Discussion (Misc queries) 3 January 15th 06 10:24 PM
prevent user from selecting and changing a sheet dirt Excel Programming 1 December 26th 04 10:17 PM
prevent user to rename sheet caroline Excel Programming 4 May 17th 04 01:29 PM
How to Prevent User from Unhiding Sheet Bruce B[_2_] Excel Programming 4 September 17th 03 10:01 AM


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

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

About Us

"It's about Microsoft Excel"