Database Workbook

R

ranswrt

I have a Database workbook that is opened by other workbooks to access the
data in it. Is it possible to make the database workbook so that it can only
be opened thru antoher workbook and not by clicking on the icon?
 
C

Chip Pearson

You can do this with the Auto_Open procedure in the data base workbook.

Sub Auto_Open()
MsgBox "This workbook cannot be opened manually"
ThisWorkbook.Close savechanges:=False
End Sub

Auto_Open is automatically executed when the workbook is opened manually,
not when it is opened via VBA code and so the code above closes the workbook
if it is opened manually. Of course, the user could defeat this by disabling
VBA code or by simply holding the SHIFT key down while opening the workbook.
However, this approach may be "good enough" for your purposes.

If you need code to run when the workbook is opened, either via VBA code and
manually, put that code in the Workbook_Open event in the ThisWorkbook
module. Workbook_Open is executed when the workbook is opened, regardless of
how it is opened.

--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top