I have an excel file with VBA script. In this script, I have a code that causes the 'save as' function to be disabled. I would like to protect this small piece of code with a password.... Is this possible? Because my co-users would also need to get into that Visual Basic Editor for other projects, so only a few lines of code need to be protected with a password.
IS it possible?
Related
Sorry to bother you, i would like to stop people from being able to write code on VBA on my excel sheet.
But I can't do it since there is no VBA code already in place.
Then you will tell me to put some useless VBA code and protect it, but i can't do it because of workplace regulations (The document is approved as an excel sheet without vba).
So what do you think are my options ?
Is there a way to stop users from writing VBA code if you have no VBA code already written ?
If i use the project properties to add a password it won't work (because no vba code is written). I have tried this several times already
Thanks a lot,
Have a great day
I'm working on an excel file, and i did a workbook_open event that show a input box to make the user enter a specific password (because each password open certain part of the file) but i have a problem that if the user doesn't enabled macro, he can see all the information in the file, so I'm looking for a way to prevent the user from read or use the file if he doesn't enabled macro.
it may be possible to protect Excel spreadsheets and this VBA code will remove the protection:
enter code here Workbooks("salary ").Worksheets("data").UnProtect Password:="xyz"
I'm afraid a password is not good enough protection for your file,
See this link:
Decoding a password that protects an Excel file(The site is not in English)
I wanted to save all my VBA Project in a Excel workbook (or other type of file if possible) and then embbed it to run in another workbook. I've seen topics about it but only found ways to run the macros opening the first sheet.
I want to run a macro from a first workbook in a second one without opening the first workbook to do it. How can I do that?
Save the file with the macros as a xlam file and Excel can load them each time Excel opens.
You need to open File -> options -> add-ins.
At the bottom there is a button Go to (or something, I don't have English Excel on the current computer.)
Then add the file to the list by clicking Browse and finding the file you just saved as xlam file.
Two scenarios comes to mind:
1) You have a second macro for personal use and can save it locally (save in: %USERPROFILE%\AppData\Roaming\Microsoft\Excel\XLSTART). This will allow you to create quick-buttons for your macros, etc. These types of macros open with Excel and will be separate VBA Projects inside of the default VBA editor.
2) You have a network or drive that multiple users need to access, so each user has a macro in their file (.xlsm or .xlsb), where that internal macro reads Application.Run "filepath\workbookname.xlsb!macro", which also allows you to call a private subroutine (note that you could use Call, but Application.Run will ensure that even Private macros are able to be accessed). This shouldn't require the other workbook be open, though I have personally had one user whose computer always opens the other file, regardless.
Edit:
Third scenario (really 2b):
3) You have files where you want to regularly access another file... you will follow a similar approach to point 2 where you make a macro to Application.Run, though you can save that macro in your XLSTART folder... this will allow you to have a source macro location where others may also want to access and utilize. The source document would allow you to maintain 1 file for many users.
Your answers were great! Great to know about XLSTART folder from #Cyril, but based on #Andreas answer I found my path.
The "problems" with adding an Add-In as #Andreas said, are cause my VBA Project would be avaliable on the VB Editor to every workbook on that computer, and to run my macros I'd have to use Application.Run("workbook.xlam!Macro").
Then I found References, which I have the same features, including I can delete my .xlam file to remove my code, and don't have the problems I mentioned above.
Adding my VBA .xlam file as an reference, it'll be avaliable only to that specific workbook and I can run my macro just like it was on the same workbook.
For general knowledge:
ADDING A REFERENCE:
1- Save your project as an Excel Add-In (.xlam file)
2- Open your target workbook, go to the Visual Basic Editor
3- Go to Tools > References > Browse... find your .xlam file and make sure it's checked.
4- Done! Now you'll see the project on the editor and can run your macros just like it was on the same workbook.
I have protected Excel VBA code with a password, which is breakable.
Now how can we delete that VBA module or code when trying to open that VBA code?
Thanks in advance.
The answer is: You just can't hide the code if someone breaks your password.
The issue is that anyone could start Excel with macros disabled. Then break your password and view your code. With macros disabled your deleting macro won't run too.
You cannot secure the code more than with that password. That's not possible.
The only secure way to hide code is not to include that code at VBA side:
What you can do to keep some algorithm code secret is creating a dll library (with any other language) that you then call from VBA. But that would only work for some functions like calculations but not for any code that interacts with worksheets. And the downside of this is that you would always need to give that dll along with your worksheet.
I have a workbook, which creates a second workbook (using ThisWorkbook.SaveCopyAs) to present the data nicely to users. It relies on macros for part of the processing.
However, I've been asked to make those macros inaccessible to users. They still need to run them, but to view/edit them should require a password. I can figure out how to do it using the GUI (VBA Editor -> right click VBAProject -> VBAProject Properties -> Protection, tick the box and enter a password), but I haven't found a way to do so using VBA. The Workbook.Protect function seems to lock down everything except VBA.
If I try to apply it to the source workbook, I get "Can't perform operation since the project is protected", so that doesn't work either.
I'm running 2010, but the workbook needs to be compatible with 2003, so no fancy new tricks. :(
This is a method that describes setting the project password without using sendkeys http://www.standards.com/Office/SetVBAProjectPassword.html
This post may be helpful to you. Note that in the comments it says you need to add vbeext1.olb.
I had a similar problem. I needed excel code to populate user created new sheets, but I wanted to password protect the project. It would work great as long as I did not use password proection, but Excel will not allow it to generate code in the new sheets with password protection.
The solution was interesting. Give your project an easy name or initials . Something people can find with ease.
You password protect your entire project and save the resulting file as an XLA (add on).
Then UNprotect the workbook, rename the file (just in case you make a mistake) and strip it of all the code, modules, classes, forms, etc. Save the new stripped Excel File.
Now open the new stripped file and add the xla in TOOLS/add ons. Then go to the VBA editor, References and find your project wiht a new name, and link (you may have to save and reopen once to find under referneces).
That's it. the new file, empty of all code, will operate using the old code but you will have no access to it without a password. At the same time, the old code can place the code on the new worksheets as before since the new workbook Project is not password protected
What I have found is that if you change locations, your users may need to find the link in the references, but I am sure you can create a macro to find and link automatically (that macro, of course, would be visible to the world).
I think this will solve any problem with protected code.
Good luck