How can we delete excel vba module when trying to see code - excel

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.

Related

Protect VBA code excel without writing VBA code

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

Protect only one VBA macro with password

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?

How to protect formulas in excel?

I have a workbook I have created with lots of different formula's. My question is, how can I stop the end user from stealing the formula's? I have had a look at: Protecting Code in an Excel Workbook?
This is generally for VBA. Is there a way to stop users doing this, or is it just worksheet protect and cross your fingers?
You probably should be more specific on what formulas are you trying to protect: Excel Worksheet formulas of the VBA code?
In general, you can create a custom VBA Add-in (i.e. .xla file) and protect it with password as per Excel documentation. In case your major concerns relate to worksheet function, then you can include them in said VBA add-in using for example, Range.Formula (re: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-formula-property-excel ) or Range.FormulaArray properties.
Hope this may help.
There is no way to fully protect formulas in Excel. For every password protection type, there is a way to break that protection. The only thing you could do if you really wanted to prevent end-users from getting the formulas is to hard-code the entire sheet before sending it to them. Of course, if the workbook relies on user input and using formulas to output an answer, that won't work.
Do you need the formulas protected for some sort of IP reason, or just to prevent people from messing them up?

Excel VBA macro not found by worksheet, #NAME

I'm trying to get a simple VBA function to run in an excel (.xlsm) worksheet.
I created this function:
Function abc()
abc = 2
End Function
in Module2, and it worked.
But after I copied the spreadsheet to another system, it now just shows "#name" as if it can't find it. The function shows up on the available list of functions however.
This makes me think there is some kind of setting I need to enable, but I've enabled whatever I was prompted for. Any ideas?
I should've known it was in the trust center:
http://office.microsoft.com/en-us/excel-help/change-macro-security-settings-in-excel-HP010096919.aspx
Basically, hit the ball and poke around until you find "trust" and "enable macros" and select the least secure options.
And then close and re-open the spreadsheet.
I think we may need more information. What version of Excel are you using? Is it different from the destination system version?
You'll want to make sure that Module2 was in the Workbook you copied into the other system. Excel 2007 stores macros on a personal workbook by default sometimes so you'll need to check the the code is actually inside of the .xlsm file.
If you're still stuck and need a quick fix just copy the code text into the new system's Excel workbook directly without making a .xlsm file (create new module in the other system then paste).
If you would like to learn how to put together add-ins you can get started here or here.

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

Resources