• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Restrict workbook open in existing excel instance

inddon

Member
Hello There,

I have two workbooks with VBA code in it. When the First file is opened (by double click the .xlsm file), it opens the 2nd related file as well. Both these files open in the same instance.

I would like to know if the below is possible to achieve, and how:
1. The above instance where the 2 workbooks are opened, no other workbooks should be allowed to be opened in that instance.

Look forward to lhearing from you.

Regards,
Don
 
Hi inddon
you should be able to capture another workbook being opened with WindowDeactivate and prevent it there if it has the wrong name perhaps.
In Thisworkbook:
Code:
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Dim SecondWB As String
SecondWB = "Workbook2.xlsm"
    If ActiveWorkbook.Name <> ThisWorkbook.Name Or ActiveWorkbook.Name <> SecondWB Then
        ActiveWorkbook.Close
    End If
    MsgBox "Please open new workbooks in a seperate instance."
End Sub
Maybe something like the above.
If this was helpful, please click 'Like' in the bottom right!

Stevie ^.^
 
Hi Stevie,

Thank you for your reply. I added the code in both the workbooks (with the file name change).
When I open a third workbook from file explorer or from a Inbox email attachment, it does give a message.

In a way I cannot open any excel file when my first and second workbook is open. When the user opens a third workbook it should automatically open in a new instance.

The catch here is when I open my first workbook (which opens the second one as well), should be in the same instance and not another instance.

How can this be done?

Regards,
Don
 
Hi Inddon,
I am not sure that you can be that specific around the opening of workbooks. If you can, then I am not sure how it would be done only for workbooks opening in a different instance as you mentioned in your second comment.
Stevie
 
Hi Inddon,
I am not sure that you can be that specific around the opening of workbooks. If you can, then I am not sure how it would be done only for workbooks opening in a different instance as you mentioned in your second comment.
Stevie


Thank you Stevie for your reply.

If I find something will post it here.

Regards,
Don
 
Back
Top