Stop the oening of another workbook in a certain instance.

bandit_1981

Board Regular
Joined
Aug 17, 2005
Messages
201
Hello all.

I am trying to keep the users from being able to have more then just my WB open in that specific instance of excel. Right now they use a small exe to load up the spread sheet and i always create a new instance of excel so there is not an issue. The issue occurs when they open my WB then instead of opening excel and putting another WB in a seperate instance they just double click it so now i have 2 WB in the same instance. This messess up my work and sometimes causes a hard Crash. Is there a way to prevent them from opening another WB in that instance?

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I am not an expert, but this seems to work:

In the workbook that you want to isolate, create a Class Module and paste this code (let's say you name it AppWithEvents):

Code:
Public WithEvents App As Application

Private Sub App_NewWorkbook(ByVal Wb As Workbook)
    If (App.Workbooks.Count > 1) Then
        MsgBox "You cannot create other workbooks in this instance!"
        Wb.Close False
    End If
End Sub

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
    If (App.Workbooks.Count > 1) Then
        MsgBox "You cannot open other workbooks in this instance!"
        Wb.Close False
    End If
End Sub

Then in the "ThisWorkbook" object of the same workbook do this:
Code:
Dim gApp As New AppWithEvents

Private Sub Workbook_Open()
    Set gApp.App = Application
End Sub

Whenever you try to open another workbook, this code will send a message to the user and close it (I don't know how to stop the open, but hopefully the effect is the same). The same will happen if you try to create a new workbook. Even when you try double clicking another Excel file (*.xls), and Windows tries to open the file with the Excel instance in which the isolated workbook is running, the open will be rejected. As usual, this won't work if the user disables the macros, but then your own macros wouldn't work either!

I hope this helps!

HW.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,178
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top