Password to protect macro used on the change event in excel - excel

I know that a vba macro can be password protected. I was wondering if the same could be applied to an event change macro? If yes then how would you go about it.

"To protect your code, open the Excel Workbook and go to Tools>Macro>Visual Basic Editor (Alt+F11). Now, from within the VBE go to Tools>VBAProject Properties and then click the Protection page tab and then check "Lock project from viewing" and then enter your password and again to confirm it. After doing this you must save, close & reopen the Workbook for the protection to take effect."
Source: http://www.ozgrid.com/VBA/protect-vba-code.htm
This was an easy google, I reccomend you look online before asking on Stack Overflow, these simple questions are generally not well received.
If your question is about protecting a specific part of your code, and not the other parts of the code, then it can't be done as far as I know.

Related

Disallow workbook editing unless Enable Content is clicked

I'm setting up a shared Excel spreadsheet with macros, but I don't want to let anyone edit the document at all until they've clicked the "Enable Content" in the SECURITY WARNING bar at the top.
How can I "protect" the workbook like that?
Set up the workbook to run a macro before the file is saved (workbook.beforesave). In that routine, set all sheets to xlVeryHidden, except for one sheet where you explain that the user needs to enable macros. You could even have a screenshot showing what they need to click.
When macros are enabled, the workbook_open event can unhide all sheets you want to show.
Protect the VBA project with a password.
Someone with very malicious intent and advanced coding skills will probably be able to find a way to circumvent this setup, but it should work well in a business environment where people just want to get their work done.

Need to disable copy/paste command on excel 2007 across different users

I need to disable the copy/paste in excel 2007. The excel file will be sent to different users so i need a solution where copy/paste is disabled for all users.
I have searched the web but everyone has asked to enable the macros but the problem with that is i will have to enable the macros for every user first before restricting them from copy/pasting.
So looking for a solution where i can write some vba code on sheet to restrict all users from copy/pasting without enabling macros.
Thanks.
Lock the Cells with the Protection Option of Excel manually or lock them programmatically.
Example:
'Range Lock
Worksheets("Sheet1").Range("A1:G37").Locked = True
'Sheet Lock
Worksheets("Sheet1").Protect
EDIT:
Just saw ur new comment, there is no option to use VBA code to block ONLY copy/pasting without allowing Macros in ur Workbook.
You don't need VBA for this.
Go to the review tab
Select protect sheet
Protect with password and take away the ✓ (there should only be one)

How to make an Excel Workbook have read-only access without C#?

We have an Excel workbook which is similar to an Error Codes database. Unfortunately the application is written in such a way similar to IF (ExceptionCode != AnyPreviousExceptionCode) THEN (Make New Exception Code) which gives the messy problem of new, never before seen exception codes appearing on our monitoring software and requiring a team of analysts to investigate. The point being that this Excel workbook of Error Codes changes alot day to day, especially if a big release comes out.
The problem I have is that there is a team who needs to have this workbook open as they need to consult what error code is what, but there is also one person who needs to update this workbook. Excel of course gives full rights to whoever opens the workbook first and everyone else has to wait, however we have a global team so it's not a simple matter of going over to someone and telling them "please can you share the workbook to me".
Is it possible in Excel to set some users as read-only and other users as write access and have this reflect on the GUI so Excel doesn't make the write access user wait for the read-only user to close the workbook?
In Win7 for Excel 2003, 2007 & 2010 there is a dropdown arrow on the right side of the open button in the open dialog. If you click that you get an option to open the file as Read-Only. Can the non editing users open it like this?
Shift+Right Click on an excel file also gives the option to open as read only.
Sorry man, did not see your question a month ago :)

Password-protect the macros of a second workbook from a first using VBA

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

Macro Edit/View Protection

I have written a VBA macro to do some stuff in Excel, and I want to know if the following is possible.
How do I protect a Macro so that no matter who uses the spreadsheet, they cannot edit the code? The protection needs to be strong enough that even if they press ALT + F11 and pull up the macro, the Edit button options need to be greyed out, even if the macro has been selected.
Also is it possible to stop a user from even seeing the code?
I think the easiest way is just to protect the workbook code. VBA Project properties -> Protection -> Lock project for viewing. You will need to specify a password.
It's not world-class protection, but it will stop the average user editing the code.

Resources