I'm building a worksheet on microsoft excel and it will deal with sensible business data. The worksheet will be placed on a USB drive and have to move from place to place constantly. Therefore I've created a feature in excel VBA to enable/disable password protection. Here is how it works.
A page named settings is xlVeryHidden containing the user's password in a cell, another cell in the page contains the word yes or no. Depending on weather password protection is activated or not. When the user first opens the Workbook all sheets are xlVeryHidden except one containing a button to continue, they click on the button which runs a macro to check weather in the settings sheet the word is yes or no. Depending on so, they are prompted with a login or all the sheets are unhidden.
The code for the login is the following:
If PasswordTextbox.Text = ThisWorkbook.Sheets("Settings").Range("J5").Value Then
And after that all sheets are unhidden. Else it will give an error Msg Box.
Also the VBA code editor will be protected with excels default system.
What I'm asking here: Is my system fairly secure? For a regular computer user would this be hard to crack?
Thanks in advance :)
I'll add that it is pretty easy to unprotect your macro to get access to your code. If possible, you should think about implementing a protected database to store your sensitive data and populate your excel file from there, after proper authentication from the user.
Related
I have an Excel Add-In which I am building which stores users settings in a Settings worksheet within the Add-In. I use the Settings sheet essentially as storage for boolean values and potentially, the user's registration details.
However, if I open up a new VBA Project and include the Add-In as a reference (In VBA: Tools > References > MY Add-In) then I can access the Settings worksheet and potentially break the password on it and hack the registration details.
The Settings sheet is set to be xlVeryHidden however it can be accessed via VBA code. Is there anyway to prevent this in Excel? In a module for example I can use the Option Private Module method.
If you password protect and lock the project then your code and the worksheet objects can't be viewed. Go to Tools > VBAObject properties > Protection tab then tick 'Lock Project For Viewing' and then set a password in 'Password to view object properties'.
However, there is nothing to stop a hacker from...
For s = 1 to Sheets.Count
Sheets(s).visible = True
Next s
...to see your Settings sheet.
There are a few options:
1) Have the settings sheet in a seperate workbook, or some other format like .txt and read from that (recommended).
2) Use some kind of encryption in your Setting sheet and decrypt it in your code, a really simple example is to use numbers in place of text so 'example' would = '5,24,1,13,16,12,5', but obviously you want to employ something more sophisticated that than and you can search online for many ways to do it.
3) Use 2, but store the decryption code somewhere else.
Be aware though, that for someone who knows what they're doing there really is no way to prevent a VBA hack, unless you use option 1/3 and have a way to store the file somewhere that isn't publicly accessible.
I have an application built in MS Excel using VBA. I originally protected some worksheets and the VBA project by password. My users can only input and use drop downs on specific cells in specific sheets. To let my VBA modify the protected sheets I had to unprotect the sheets and then reprotect them using the password.
The requirement of the project has now changed and now requires me not to have a hard coded string for the password in the code to protect and unprotect the sheets.
A code sample of what is going on in my VBA code is the following.
Worksheets("Loading").Unprotect ("****")
[Functional Code]
Worksheets("Loading").Protect ("****")
Considering that I have to have the password to gain access to the VBA project is there a way to allow the project to interact with protected sheets as if they were not protected?
If no. Is there another method of preventing user interaction with a sheet while not inhibiting VBA interaction ( Very hidden would not work for the user still needs to see the sheet ).
Side note: This needs to prevent a normal person with minimal technical skills from altering the sheets in ways that they shouldn't
On an unprotected worksheet use,
Worksheets("Loading").Protect Password:=****, UserInterfaceOnly:=True
See Worksheet.Protect method for full details. Once it has been set with this extra parameter and the workbook has been saved, the protection will be bypassed by any VBA code but remain in place for user interaction.
I have a workbook that contains several (lookup) tabs that I don't want any users to be able to unhide. However, there is one tab that contains admin info that I would like admin users to be able to see. I have a button and macro that prompts for an admin password before unhiding this tab, but if I protect the workbook structure (so that hidden tabs are not accessible for other users) the vba fails. Is there no way to protect/unprotect the workbook from within the admin macro? I have tried various combinations of ActiveWorkbook.Unprotect, ActiveWorkbook.Protect and ActiveWorkbook.ProtectStructure to no avail - both within the admin macro and WorkbookOpen. The error msg I most commonly encounter is "Can't assign to read-only property" even after having ActiveWorkbook.Unprotect at the top of my code. Does anyone know how to work around this? I don't really want to have to leave all tabs open to being unhidden with a second password on the Admin worksheet itself - clumsy!
Instead of protecting the whole workbook, set the Visible property of the sheets you want to hide to xlSheetVeryHidden - you can do this manually in the properties window of the VBA editor. Now those sheets won't show up in the Unhide… dialog. Your macro could swap the visibility of your admin-only sheet from xlSheetVeryHidden to xlSheetVisible and back.
By itself this doesn't protect your workbook from a user who knows how to access the VBA editor and properties, but if you need to do that there seem to be a lot of answers to a quick web search - it may depend on your version of Excel.
I have an excel macro-enabled sheet that users open, fill out a list of information (name, date, etc) and click a save button. This creates a new file name based on the information, and saves the file to a network location. The users then continue to work with the sheet.
I forced the users to enable macros (excellent tutorial here: http://datapigtechnologies.com/blog/index.php/forcing-your-clients-to-enable-macros/) and that works well, however once the file name changes, macros are disabled. I assume this due to the fact that it is an untrusted network location. The sheet will be used by many different computers, so I would like to find a vba workaround rather than relying on an excel setting.
Edit: I think I have the answer: As #mehow said based on the link I have posted, I can first run the part of the macro that finds the file name, then lock the workbook all except the start page, then save the workbook as the new name, then hide the start page and show everything else. That way if macros are disabled once the sheet is saved it should force the user to re-enable without compromising the protection. I'll post once I find outwhether it will work.
Edit: It works! Thanks.
I have an excel tool that gathers information from a user based on their login information. The information is stored in cells on one of the worksheets. If I wanted to lock these cells so they can't be updated manually, how can I go about doing that? If someone else logs in, obviously these cells would change. I hope to do it through VBA.
I only want to lock 6 cells... everything else should be editable...
Thanks
You can protect the worksheet with a password like this:
Private Sub Workbook_Open()
Sheets("sheetName").Protect Password:="YourPassword", UserInterfaceOnly:=True
End Sub
That will prevent users from manually making changes to the worksheet without entering the password. Your VBA code will still be able to make changes because you've set UserInterfaceOnly to True.
Note that users could easily view this password by navigating to the code through the Visual Basic editor. You can password protect the code as well, though: just right-click on the module, click on VBAProject Properties and go to the Protection tab.
See this page for more information: Excel VBA: Macro Code To Run Macros On Protected Worksheets & Sheets.
If these cells are the only ones on the sheet you want to protect, then just change the cell properties of the remaining cells by changing Locked property to false and leave the cells in question as Locked then protect the sheet using UserInterfaceOnly set to true (but realize that this doesn't work for all possible macro changes, so I usually avoid it.)
There are other methods that could work, but I think this is the best solution for you. If not, please add a comment to let me know.