Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Writing dynamic code - problem with VBA project protection

Hi people

I've written a function that writes another function in a module.
When i run it the VB editor appears - which i dont want to happen, as the
underlying code is of no interest to the users.

Can i either close it dynamically or stop it from opening?

I think the problem is even worse than this because the finished spreadsheet
really needs to be tamper proof (for that read "idiot-proof" - obviously
anyone who knows what they're doing should be able to get in).

When the VBA project is protected it comes back with run-time error 50289
"Can't perform operation since the project is protected". And as it appears
that i can't programmatically unprotect the project:
http://www.j-walk.com/ss/excel/faqs/...tionFAQ.htm#P3
... then it looks like i'm done for?

There must be some workaround surely?


Thanks in advance

Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Writing dynamic code - problem with VBA project protection

Hi
some code workarounds for you (esp. for the first issue I'm also looking for
something better)
1. VBE Editor:

sub foo()
dim oState
oState = Application.VBE.MainWindow.Visible
'...
'some code
'...
If Not (oState) Then
Application.VBE.MainWindow.Visible = False
End If
end sub

2. VBA project protected: Some code to check if it is protected
'---------------------------------------------------------------------------
Private Function VBAccessAllowed()
'---------------------------------------------------------------------------
' Function : Test VBA security settings to see if we can modify
' VBA code (caused by A new security setting in
' Excel 2002: Trust access to Visual Basic Project
' Synopsis: If Version = 10
' Try and set an object to a workbook project and
' test whether it works or not.
' If fail, show messgae and return False.
' Returns: True/False - default True
'---------------------------------------------------------------------------

Dim VBProject As Object ' as VBProject
Dim sMsg As String

VBAccessAllowed = True
If Val(Application.Version) = 10 Then
On Error Resume Next
Set VBProject = ActiveWorkbook.VBProject
If Err.Number < 0 Then
sMsg ="Project protected"
msgbox sMsg
VBAccessAllowed = False
End If
End If

'clear variables
Set VBProject = Nothing
End Function






"pauly" wrote:

Hi people

I've written a function that writes another function in a module.
When i run it the VB editor appears - which i dont want to happen, as the
underlying code is of no interest to the users.

Can i either close it dynamically or stop it from opening?

I think the problem is even worse than this because the finished spreadsheet
really needs to be tamper proof (for that read "idiot-proof" - obviously
anyone who knows what they're doing should be able to get in).

When the VBA project is protected it comes back with run-time error 50289
"Can't perform operation since the project is protected". And as it appears
that i can't programmatically unprotect the project:
http://www.j-walk.com/ss/excel/faqs/...tionFAQ.htm#P3
... then it looks like i'm done for?

There must be some workaround surely?


Thanks in advance

Paul



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help writing Code LeAnne Excel Discussion (Misc queries) 1 February 15th 08 03:27 PM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM
VB project protection Frank C. Excel Programming 2 January 12th 04 02:29 PM
Discussion: VBA Project Code Protection Edwin Tam (MS MVP) Excel Programming 2 November 14th 03 01:24 PM
Please help Frustrating VBA code writing problem [email protected] Excel Programming 1 August 7th 03 05:23 PM


All times are GMT +1. The time now is 09:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"