Solved

Excel - VBA - Prevent files being opened into Excel Session

Posted on 2000-03-01
3
492 Views
Last Modified: 2010-05-18
I have developed an integrated excel workbook with customised toolbars.  When the workbook opens it runs code to hide all microsoft toolbars and opens the customised toolbars.

I would like to be able to prevent users of the spreadsheet opening any other files while the spreadsheet is open (eg if a user double clicks on an excel file in explorer it would normally open the excel file into the current Excel session - is it possible to have this file redirected into another session of excel - ie the user would see the normal excel workspace or at least prevent the file being opened.
0
Comment
Question by:dhadland
  • 2
3 Comments
 
LVL 17

Expert Comment

by:calacuccia
ID: 2574806
Hi dhadland,

In the workbook specified you have to do following things:

1) Add a class module (right click on project in porject tree, Inert/Class Module)

2) In the class module, called Class1 by default, insert this code, it will close the opened workbook straight away.

Public WithEvents App As Application

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
ActiveWorkbook.Close
End Sub

3) In any of your normal modules, enter this code:

Dim X As New Class1

Sub InitializeApp()
    Set X.App = Application
End Sub

4) In the list of code runned on the workbook open event (the workbook you specified above), call the InitializeApp macro, just adding the line

InitializeApp

in one of the macros which runs on opening the workbook


This is sufficient to prevent the user from opening other files or from within Excel, or from the Explorer. It's necessary to run the InitializeApp macro to activate the application defined as App.

Now how to open another Excel instance, I'm not sure yet. I'm well acquinted with Excel VBA, but not if going outside.

Good Luck

Calacuccia
0
 
LVL 17

Accepted Solution

by:
calacuccia earned 50 total points
ID: 2574818
Apologies for the typing errors.
0
 
LVL 1

Author Comment

by:dhadland
ID: 2585644
Calcuccia

Thanks for help.

Comment -  the code closed files inlcuding the one the code is in - so added an IF statement to the -

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
     ActiveWorkbook.Close
End Sub

to exclude the main  file.

dhadland
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL store procedure to calculate and return result 6 56
Protecting vb6 & .Net code Obfuscation 18 121
Recommendation vb6 to vb.net or others 14 142
Automatic Email Reminder 4 36
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now