Only open if file is in a certail location with a certain filename

RhodEvans

Board Regular
Joined
Oct 31, 2012
Messages
88
Evening,I have got a spreadsheet with highly restricted information in it, as such I am trying to lock it down as much as possible.So far I have stopped copying and pasting, printing and saving to other location or with other filenames.Is there a bit of code that I can put (I assume in the open section) that will close the spreadsheet if the file name and location do not match a predefined sample (written in the code as then I can hide it?)Also in an ideal world there would be a bit of code that makes the spreadsheet unusable if macro's are disabled. I'm vaguelly thinking to hide the spreadsheets unless the macro runs to unhide them. But any better ideas from the 'God's of Excel' that are on this forum would be most appreciated.As always, thanks in advance!!!!!!Rhod
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
here is what I have so far:

Private Sub Workbook_Activate()Dim oCtrl As Office.CommandBarControl'Disable all Cut menusFor Each oCtrl In Application.CommandBars.FindControls(ID:=21)oCtrl.Enabled = FalseNext oCtrl'Disable all Copy menusFor Each oCtrl In Application.CommandBars.FindControls(ID:=19)oCtrl.Enabled = FalseNext oCtrlApplication.CellDragAndDrop = FalseApplication.OnKey "^x", ""Application.OnKey "^c", ""End SubPrivate Sub Workbook_BeforePrint(Cancel As Boolean)Cancel = TrueEnd SubPrivate Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)If SaveAsUI = True Then Cancel = TrueEnd SubPrivate Sub Workbook_Deactivate()Dim oCtrl As Office.CommandBarControl'Enable all Cut menusFor Each oCtrl In Application.CommandBars.FindControls(ID:=21)oCtrl.Enabled = TrueNext oCtrl'Enable all Copy menusFor Each oCtrl In Application.CommandBars.FindControls(ID:=19)oCtrl.Enabled = TrueNext oCtrlApplication.CellDragAndDrop = TrueApplication.OnKey "^x"Application.OnKey "^c"End SubPrivate Sub Workbook_Open()Dim oCtrl As Office.CommandBarControl'Disable all Cut menusFor Each oCtrl In Application.CommandBars.FindControls(ID:=21)oCtrl.Enabled = FalseNext oCtrl'Disable all Copy menusFor Each oCtrl In Application.CommandBars.FindControls(ID:=19)oCtrl.Enabled = FalseNext oCtrlApplication.CellDragAndDrop = FalseApplication.OnKey "^x", ""Application.OnKey "^c", ""End Sub
 
Upvote 0
Re: here is what I have so far:

Does anyone have any ideas on how to force close a preadsheet if the path and filename do not match to what you want it to? I was surprised that I couldn't find any ideas on the internet for this.Thanks in advance Rhod
 
Upvote 0
Sorry, but I'm getting desperate. Even an answer of, no this is not possible would do. That way at least I can stop thinking about this problem and get on with my life!?
 
Upvote 0
Even if you secure the workbook to the Nth degree, all a user has to do is not enable macros and all your efforts are defeated...

...would be a bit of code that makes the spreadsheet unusable if macro's are disabled
Unfortunately, this is not an ideal world.
 
Upvote 0
Don't have much time to assist but you may find answer to one of your requirments here:
VBA Express : Excel - Force users to enable macros in a workbook

Also, if your data is that confidential then you should not consider Excel as a secure platform to store it.
Protection is really only designed as a means to prevent general users from doing something you don't want them to do not from keeping out those that know what their doing out.

Hope helpful

Dave
 
Upvote 0
I have now managed to make the workbook unusable if macro's are disabled (and will gladly post the website where I found it if anyone wants it). Using the XLveryhidden command. Now I am just looking for a way of force closing the spreadsheet, it the workbook does not have a specific filename and is not in a specific location.
 
Upvote 0
Well as a starter, you can use ThisWorkbook.FullName to get the saved path and name of workbook as long as it has been saved.

Though as cytop states, Excel security is extremely trivial to overcome, the user doesn't even need code; so you might be better looking at another platform. Can't you just put it in a network location the wrong people dont have access to?
 
Upvote 0
The spreadsheet should only be on a secure network. The idea why I am looking for this piece of code is not so much to stop maliscious people, it is more to stop and deter the people who do have access to it (and thankfully they have far far far less excel knowledge), from thinking it would be much easier to also have a copy on their work laptop which leave the security of the office and network.
 
Upvote 0

Forum statistics

Threads
1,216,131
Messages
6,129,066
Members
449,485
Latest member
greggy

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