ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   locking vba code (https://www.excelbanter.com/excel-programming/354900-locking-vba-code.html)

john tempest[_2_]

locking vba code
 
i have locked and password protected my code in a worksheet. when i remove
this worksheet from the worbook and save it the protection is not there.
can anybody help
thankyou john tempest

Tom Ogilvy

locking vba code
 
Protection is done at project level - so for the whole workbook.

I have never tried it, but if your project is protected and you can copy a
sheet with code out of the workbook and the code is accessible, that sounds
like a flaw in the protection scheme. I would expect either the sheet
couldn't be copied or the code would not be copied with it.

--
Regards,
Tom Ogilvy



"john tempest" wrote in message
...
i have locked and password protected my code in a worksheet. when i remove
this worksheet from the worbook and save it the protection is not there.
can anybody help
thankyou john tempest




john tempest[_2_]

locking vba code
 
this is the code i use to copy and save the worksheet,could there be a flaw
in the code
Private Sub CommandButton1_Click()
Dim wkbk As Workbook, sh As Worksheet
Worksheets("MANUAL TS").Copy
Set wkbk = ActiveWorkbook
' get rid of all cell formulas
For Each sh In wkbk.Worksheets
With sh.UsedRange
.Value = .Value
'getrid of command button'
ActiveSheet.OLEObjects("CommandButton1").Delete
'protect sheet'
ActiveWorkbook.Sheets("MANUAL TS").Protect
Password:="AABAABABBBAW"


End With
Next
wkbk.SaveAs "C:\Documents and Settings\Administrator\My
Documents\HOWDENS\TIMESHEET\ " & Sheets("MANUAL TS").Range("B5") & ".xls"
wkbk.Close
End Sub
any ideas
thankyou john tempest

"Tom Ogilvy" wrote:

Protection is done at project level - so for the whole workbook.

I have never tried it, but if your project is protected and you can copy a
sheet with code out of the workbook and the code is accessible, that sounds
like a flaw in the protection scheme. I would expect either the sheet
couldn't be copied or the code would not be copied with it.

--
Regards,
Tom Ogilvy



"john tempest" wrote in message
...
i have locked and password protected my code in a worksheet. when i remove
this worksheet from the worbook and save it the protection is not there.
can anybody help
thankyou john tempest





Tom Ogilvy

locking vba code
 
I ran your code with the project protected for viewing in the VBE and it did
copy the worksheet and its code (the code in the sheet module) to the new
workbook and the code was able to be viewed. I guess you will have to
expand your code to strip the code in the copy. See Chip Pearson's page on
this and related topics

http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy


"john tempest" wrote in message
...
this is the code i use to copy and save the worksheet,could there be a

flaw
in the code
Private Sub CommandButton1_Click()
Dim wkbk As Workbook, sh As Worksheet
Worksheets("MANUAL TS").Copy
Set wkbk = ActiveWorkbook
' get rid of all cell formulas
For Each sh In wkbk.Worksheets
With sh.UsedRange
.Value = .Value
'getrid of command button'
ActiveSheet.OLEObjects("CommandButton1").Delete
'protect sheet'
ActiveWorkbook.Sheets("MANUAL TS").Protect
Password:="AABAABABBBAW"


End With
Next
wkbk.SaveAs "C:\Documents and Settings\Administrator\My
Documents\HOWDENS\TIMESHEET\ " & Sheets("MANUAL TS").Range("B5") & ".xls"
wkbk.Close
End Sub
any ideas
thankyou john tempest

"Tom Ogilvy" wrote:

Protection is done at project level - so for the whole workbook.

I have never tried it, but if your project is protected and you can copy

a
sheet with code out of the workbook and the code is accessible, that

sounds
like a flaw in the protection scheme. I would expect either the sheet
couldn't be copied or the code would not be copied with it.

--
Regards,
Tom Ogilvy



"john tempest" wrote in message
...
i have locked and password protected my code in a worksheet. when i

remove
this worksheet from the worbook and save it the protection is not

there.
can anybody help
thankyou john tempest







John Gunther

locking vba code
 
One way to work around this problem is to obfuscate (= replace with
functionally equivalant, but much harder to understand) the VBA code
within the entire Workbook. That way, even if they get at your code,
it's much harder for them to understand it.

An open source Excel/VBA source code obfuscation Add-in is available
at:

http://invisiblebasic.sourceforge.net

Just use the Add-in's "Save Invisibly As" command before sending out
your workbook.

John



All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com