Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Blocking a second spreadsheet from opening

I have several spreadsheets which run macros, some of which conflict with
each other. I was wondering if there was some code I could add to existing
macros to block a user from opening a second spreadsheet while one of these
is opened. Any help appreciated.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Blocking a second spreadsheet from opening

McBarker,

Try these - the first macro disables the Open tool, the Open command from
the File menu and the Control+0 keyboard shortcut. the second macro
re-enables everything.

Regards

Pete

Sub OpenDisable()
Dim oCtrl As Office.CommandBarControl
For Each oCtrl In Application.CommandBars.FindControls(ID:=23)
oCtrl.Enabled = False
Next oCtrl
Application.OnKey "^{o}", "" 'disable Open keyboard shortcut
End Sub

Sub OpenEnable()
Dim oCtrl As Office.CommandBarControl
For Each oCtrl In Application.CommandBars.FindControls(ID:=23)
oCtrl.Enabled = True
Next oCtrl
Application.OnKey "^{o}" 'enable Open keyboard shortcut
End Sub


"McBarker" wrote:

I have several spreadsheets which run macros, some of which conflict with
each other. I was wondering if there was some code I could add to existing
macros to block a user from opening a second spreadsheet while one of these
is opened. Any help appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Blocking a second spreadsheet from opening

McBarker,
You can either put some code in the Workbook_Open event, to check which WBs
are already open and advise the user.
Or use Application level events so Excel will trigger and you can check
whether the open should be allowed or not.
http://www.cpearson.com/excel/AppEvent.htm

NickHK

"McBarker" wrote in message
...
I have several spreadsheets which run macros, some of which conflict with
each other. I was wondering if there was some code I could add to existing
macros to block a user from opening a second spreadsheet while one of

these
is opened. Any help appreciated.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Blocking a second spreadsheet from opening

Thanks guys. I'll try the code below next week, and see if it works out. One
of the problems is that the spreadsheets in question are opened from a
desktop shortcut, which would bypass the Excel menu and toolbar commands.
Something along the lines of the following pseudocode would make what I'm
looking for easier:

[1] Spreadsheet1 is in use
[2] User opens Spreadsheet2 (from desktop shortcut)
[3] Code in the Spreadsheet2 Auto_Open() macro detects that Spreadsheet1 is
already open and in use
[4] A warning message is displayed
[5] Spreadsheet2 automatically closes

I'm just not sure of how to code line [3].

Regards
McBarker

Peter Rooney wrote:
McBarker,

Try these - the first macro disables the Open tool, the Open command
from the File menu and the Control+0 keyboard shortcut. the second
macro re-enables everything.

Regards

Pete

Sub OpenDisable()
Dim oCtrl As Office.CommandBarControl
For Each oCtrl In Application.CommandBars.FindControls(ID:=23)
oCtrl.Enabled = False
Next oCtrl
Application.OnKey "^{o}", "" 'disable Open keyboard shortcut
End Sub

Sub OpenEnable()
Dim oCtrl As Office.CommandBarControl
For Each oCtrl In Application.CommandBars.FindControls(ID:=23)
oCtrl.Enabled = True
Next oCtrl
Application.OnKey "^{o}" 'enable Open keyboard shortcut
End Sub


"McBarker" wrote:

I have several spreadsheets which run macros, some of which conflict
with each other. I was wondering if there was some code I could add
to existing macros to block a user from opening a second spreadsheet
while one of these is opened. Any help appreciated.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Blocking a second spreadsheet from opening

I need help with line 3 of the following:

[1] Spreadsheet1 is already in use
[2] User opens Spreadsheet2 (from desktop shortcut - bypassing Excel menus)
[3] Code in the Spreadsheet2 Auto_Open() macro detects that Spreadsheet1 is
already open and in use
[4] A warning message is displayed
[5] Spreadsheet2 automatically closes

Regards
McBarker


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
blocking cells from view in a spreadsheet Tini Excel Discussion (Misc queries) 4 June 3rd 09 10:18 PM
Registry policy setting is blocking opening lotus in Excel rob1047 Excel Discussion (Misc queries) 0 December 6th 07 08:04 PM
#REF! after opening a spreadsheet AG Excel Discussion (Misc queries) 0 April 27th 07 08:20 PM
opening a spreadsheet stumped New Users to Excel 2 June 10th 06 02:02 AM
Opening a spreadsheet Multiple speadsheets Excel Discussion (Misc queries) 1 March 8th 06 05:15 PM


All times are GMT +1. The time now is 11:36 AM.

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"