Does VBA only let you protect the entire Project?

eliz

New Member
Joined
Sep 12, 2006
Messages
46
I have written code for another user, I don't want them to be able to access/edit (they could view it) the code. But what if they write their own macros?
It seems it only allows protection on the entire file, not on individual procedures? Is this correct?

Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Can you please explain in more depth.
I've used a couple of built-in Add-ins (i.e. Solver, Template Wizard), but I've never created an Add-In before. BTW I'm using version 2003.

Thanks,
Eliz
 
Upvote 0
If you just place the macro code in modules in a workbook, protect the project, then File > Save as and select the last option Add-in *.xla.

Copy the .xla file to the other user's PC, open Excel, Tools > Add-ins and browse to select the .xla file.

They won't be able to view your code but will be able to view their own.
 
Upvote 0
Does VBA only let you protect the entire Project

Thank you,

I will give that a try.
Eliz
 
Upvote 0
I Saved File as an Add-In Now Code doesn't Work

Hi VoG II

I tried creating an Add-In to store my code.
Now my code doesn't seem to work.

My code loops through each sheet and therefore was being store in "ThisWorkbook" and is triggered on the Open & Save events for the file.

It wasn't being stored in a separate module.

It has to work for a variety of different files for different users, so I want it to remain pretty general.

Thanks,
Eliz

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
' for SoX high-risk spreadsheets, Elizabeth McLeod Sep-14-06

'reduce screen flicker
Application.ScreenUpdating = False

'declare variables
Dim SH As Worksheet
Dim rng As Range

On Error Resume Next

'loop through each sheet, lock formulas, protect sheets
For Each SH In Worksheets
SH.Unprotect

With SH.UsedRange
.Locked = False
Set rng = Nothing
Set rng = .SpecialCells(xlCellTypeFormulas)
If Not rng Is Nothing Then
'rng.Font.ColorIndex = 7 'optional changes color of all formulas
rng.Locked = True
End If
End With

' allow users to still insert rows with protection on
SH.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowInsertingColumns:=True, AllowInsertingRows:=True

Next SH

Application.ScreenUpdating = True

End Sub
Private Sub Workbook_Open()
' for SoX high-risk spreadsheets, Elizabeth McLeod Sep-14-06

'reduce screen flicker
Application.ScreenUpdating = False
Application.CommandBars("Protection").Visible = True

'declare variables
Dim SH As Worksheet
Dim rng As Range

On Error Resume Next

'loop through each sheet, lock formulas, protect sheets
For Each SH In Worksheets
SH.Unprotect

With SH.UsedRange
.Locked = False
Set rng = Nothing
Set rng = .SpecialCells(xlCellTypeFormulas)
If Not rng Is Nothing Then
'rng.Font.ColorIndex = 7 'optional changes color of all formulas
rng.Locked = True
End If
End With

' allow users to still insert rows with protection on
SH.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowInsertingColumns:=True, AllowInsertingRows:=True

Next SH

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Ah, I was assuming the code was in a standard module, not in the workbook's code. I don't think that an Add-in will work in your situation. sorry for leading you down the wrong path.
 
Upvote 0
Yes, you can password protect individual modules in the project. Insert a Standard Module, Using the VBA Editor ToolBar: Insert - Module [You can rename it if you want] Then add your code to it, adjust any Sheet Module code to work in the Standard Module.

Then from the Project Manager [the list of Modules in your Workbook in the Editor] Right-Click that Module and Select "VBAProjectProperties..." and then the Protection tab. Now your user can add or edit any other modules and yours will be protected!

For ThisWorkbook and Sheet Module Events Use the Events but move the code to your protected Module and add to a Sub. Then from the Event call the Sub in your protected Module. The code will run from the Event through the Call and the User will not be able to see the actual code.

You could also protect the ThisWorkbook Module if you like, then the User will only be able to add Standard modules, Forms, Classes and use any Sheet Module that you did not protect!
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,261
Members
448,558
Latest member
aivin

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