Workbook_Open() of locked project causing errors

C

Craig

I have a toolbar that runs macros from a locked project of an .xls
file that is always in a standard location. In this .xls file, under
the ThisWorkbook page, one subroutine is:

Private Sub Workbook_Open()
If Not DEVELOPER Then
Me.ChangeFileAccess Mode:=xlReadOnly
EndIf
EndSub

This is to prevent people from editing the .xls file with the macros
unless they set the DEVELOPER flag to true, which can only be done if
you have the password to unlock the project. If this flag is set to
false, as it is by default, as soon as you click a toolbar button, the
workbook for the .xls file containing the macros will open in the
background, run this routine and set itself to read-only.

This worked fine with Excel 2000. However, when we switched over to
Excel 2003, when you click the toolbar button and accept the security
warnings, it says "Compile error in hidden module: ThisWorkbook".
After more security warnings, it says it can't find the macro (I'm
assuming this is only because of the former error). As soon as I
unlock the project for viewing, everything works fine. Can anybody
tell me how to fix this (other than the obvious setting the file as
read-only rather than doing it in the code)?

Thanks in advance.
 
T

Tim Zych

Are there any MISSING references on XL2003? (VBE Tools -> References) If so
they should be unchecked or corrected depending on what they are.

Also, does the project compile without fail? Option Explicit must be at the
top of every module including ThisWorkbook and the sheets if they have code,
then VBE Debug -> Compile <vba project>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top