Only allow file to be open from another file

hungledink

Board Regular
Joined
Feb 20, 2012
Messages
88
Office Version
  1. 365
I was wondering if someone could provided some assistance in a project I've been asked to look at for work.

Essentially, I want to create 2 workbooks. One will be a database, that just stores data, and the second will be an input sheet, where users will add data that gets added to the database. I want to keep the database separate to maintain the integrity of the data

I'd like to make it so that the database can only be opened and viewed by a button on the input sheet workbook. This will then switch to the database file where they can view the desired info, and then switch back.

I do know a bit of vba so I can get the database to open when the input sheet is open, but then have it hidden. I've also got the buttons working to switch between the files.

The problem I'm having is how to stop the database file being opened as a standalone workbook.

Can anyone advise? Its something I'm working on at work so unfortunately can post the existing code.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
This code will prevent people accidentally opening the workbook, but it is easily overcome by preventing macros from running when you open the workbook, it closes the workbook if "Book1" is not open

VBA Code:
Private Sub Workbook_Open()
For Each wb In Application.Workbooks
  If wb.Name = "Book1.xlsm" Then       ' set this to the input sheet workbook
  Exit Sub
  End If
Next
Workbooks("openclose.xlsm").Close SaveChanges:=False   ' set this to your database workbook
End Sub
Put this code in the workbook module of your database workbook
 
Upvote 0
Thanks for the suggestion.
I forgot to mention in the initial question though that the input sheet isn't always going to be the same name so this won't work 8n that scenario
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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