Compiling sub routines


#1

This sub routine CANNOT be renamed because it is triggered on the workbook opening. How do I compile in VBA compiler? What do I paste into the compiler window & what do I put back into the VBA editor in my original spreadsheet before compiling the exe?

Private Sub Workbook_Open()
ThisWorkbook.Unprotect (“password”)
For Each wsSht In Workbooks(“Local Book 1.xlsm”).Worksheets
If Not wsSht.Name = “Simon” Then wsSht.Visible = xlSheetVeryHidden
Next wsSht
ThisWorkbook.Protect “password”, True
End Sub


#2

For Each isn’t supported by the VBA compiler. You should replace it with something like this:

Sub MyOpenWorkbook
 Application.ThisWorkbook.Unprotect ("password")
 For wsSht = 1 TO Application.Workbooks("Local Book 1.xlsm").Worksheets.Count 
  If Not Application.Workbooks("Local Book 1.xlsm").Worksheets(wsSht).Name = "Simon" Then Application.Workbooks("Local Book 1.xlsm").Worksheets(wsSht).Visible = xlSheetVeryHidden
 Next 
 Application.ThisWorkbook.Protect("password", True)
                               
End Sub     

Then, in your real VBA project, replace your code with:

' This function lets you call VBA macros compiled with XLS Padlock
Public Function CallXLSPadlockVBA(ID As String, Param1)
Set XLSPadlock = Application.COMAddIns("GXLSForm.GXLSFormula").Object
CallXLSPadlockVBA = XLSPadlock.PLEvalVBA(ID, Param1)
End Function


Private Sub Workbook_Open()
res = CallXLSPadlockVBA("MyOpenWorkbook", "")
Application.Calculate
End Sub

#3

You are defeating the point…the software dont allow to open it so why encrypt your open routine ?Makes sense for important macros