Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Checking for security level to allow macros to run

Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Checking for security level to allow macros to run

Hi Klaus

You can hide all sheets exept one
On that sheet you put a messege like "you must eneble macro's to work with this workbook"

Then in the workbook open event unhide the sheets and in the before save event hide them


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message ...
Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Checking for security level to allow macros to run

On Mon, 11 Jul 2005, Klaus wrote:

Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?


This is what I use (unwrap wrapping in MsgBox):

Function DoesProjectExist(AddInName As String) As Boolean
' addin name is case sensitive. is project name, not file name
Dim W As Object
DoesProjectExist = False
On Error GoTo ErrSection
For Each W In Application.VBE.VBProjects
If W.Name = AddInName Then DoesProjectExist = True
Next
Exit Function

ErrSection:
MsgBox "In order for this to work properly you need to change a
setting. Go to Tools - Macros - Security... - Trusted Sources tab. Then
both boxes at the bottom have to be checked.", vbCritical, "Macros Are Not
Trusted Source"

End Function

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Checking for security level to allow macros to run

I'm not sure how I can use this technique to check for the security level.
Klaus

"Ron de Bruin" wrote:

Hi Klaus

You can hide all sheets exept one
On that sheet you put a messege like "you must eneble macro's to work with this workbook"

Then in the workbook open event unhide the sheets and in the before save event hide them


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message ...
Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Checking for security level to allow macros to run

I can see this working for "Trusted Sources", but that is not my case. All I
can do is try to check for the Security Level. Any ideas?
Klaus

"Don Wiss" wrote:

On Mon, 11 Jul 2005, Klaus wrote:

Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?


This is what I use (unwrap wrapping in MsgBox):

Function DoesProjectExist(AddInName As String) As Boolean
' addin name is case sensitive. is project name, not file name
Dim W As Object
DoesProjectExist = False
On Error GoTo ErrSection
For Each W In Application.VBE.VBProjects
If W.Name = AddInName Then DoesProjectExist = True
Next
Exit Function

ErrSection:
MsgBox "In order for this to work properly you need to change a
setting. Go to Tools - Macros - Security... - Trusted Sources tab. Then
both boxes at the bottom have to be checked.", vbCritical, "Macros Are Not
Trusted Source"

End Function




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Checking for security level to allow macros to run

Hi Klaus

A workeround is to hide all sheets exept one with a message
and unhide them in the workbook open event.
And hide them in the beforeclose event when you close the file
So the user can't use the workbook if he disable macro's.
If he do the workbook open event don't run so there are no sheets to work
with

Some example code to do this
Sheet 1 stay always visible (message sheet)

Sub HidealmostAll()
Dim a As Integer
For a = 2 To Sheets.Count
Sheets(a).Visible = xlSheetVeryHidden
Next a
End Sub

Sub ShowAll()
Dim a As Integer
For a = 2 To Sheets.Count
Sheets(a).Visible = True
Next a
End Sub


See this page for information about events
http://www.cpearson.com/excel/events.htm





--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message ...
I'm not sure how I can use this technique to check for the security level.
Klaus

"Ron de Bruin" wrote:

Hi Klaus

You can hide all sheets exept one
On that sheet you put a messege like "you must eneble macro's to work with this workbook"

Then in the workbook open event unhide the sheets and in the before save event hide them


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message ...
Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Checking for security level to allow macros to run

Thanks I'll give that a try and see if I can get it to work.
Thanks for your patience. I'm slow but my work is poor.
Klaus

"Ron de Bruin" wrote:

Hi Klaus

A workeround is to hide all sheets exept one with a message
and unhide them in the workbook open event.
And hide them in the beforeclose event when you close the file
So the user can't use the workbook if he disable macro's.
If he do the workbook open event don't run so there are no sheets to work
with

Some example code to do this
Sheet 1 stay always visible (message sheet)

Sub HidealmostAll()
Dim a As Integer
For a = 2 To Sheets.Count
Sheets(a).Visible = xlSheetVeryHidden
Next a
End Sub

Sub ShowAll()
Dim a As Integer
For a = 2 To Sheets.Count
Sheets(a).Visible = True
Next a
End Sub


See this page for information about events
http://www.cpearson.com/excel/events.htm





--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message ...
I'm not sure how I can use this technique to check for the security level.
Klaus

"Ron de Bruin" wrote:

Hi Klaus

You can hide all sheets exept one
On that sheet you put a messege like "you must eneble macro's to work with this workbook"

Then in the workbook open event unhide the sheets and in the before save event hide them


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message ...
Is there any way to check programmatically, if the security level is set to
allow macros to run, and then 1) display a message indicating that the
security level must be set to medium and/or the macros must be enabled; and
2) stop any activity on the workbook and force the user to restart excel with
macros enabled?






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Checking for security level to allow macros to run

Hi Klaus,

The only way to know if macros are enabled or not is to try it. If your
code is running, there is no point in checking the security level, as you
know macros are enabled. If macros are disabled, then there is no code in
the world that will work, as it will never run.

Ron's advice is sound, and is often used to "lock down" a workbook.
Basically, you lock down your workbook with protection, hiding the relevant
worksheets/etc. In the Workbook_Open event, you show all the sheets and run
whatever code you need to run in order to allow for user interaction. If
macros are disabled, your code will not be triggered, and all the user will
be left with is a message on the worksheet that he/she must enable macros in
order to use the workbook.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Klaus wrote:
I'm not sure how I can use this technique to check for the security
level. Klaus

"Ron de Bruin" wrote:

Hi Klaus

You can hide all sheets exept one
On that sheet you put a messege like "you must eneble macro's to
work with this workbook"

Then in the workbook open event unhide the sheets and in the before
save event hide them


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Klaus" wrote in message
...
Is there any way to check programmatically, if the security level
is set to allow macros to run, and then 1) display a message
indicating that the security level must be set to medium and/or the
macros must be enabled; and 2) stop any activity on the workbook
and force the user to restart excel with macros enabled?


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
Macros/Security Level Freida Excel Discussion (Misc queries) 1 November 5th 07 05:52 PM
Read security level Ambika Excel Programming 1 November 25th 03 07:43 AM
Changing security level Trevor Shuttleworth Excel Programming 2 August 22nd 03 08:54 PM
Changing security level Dan E[_2_] Excel Programming 0 August 22nd 03 06:36 PM
Changing security level steve Excel Programming 0 August 22nd 03 06:32 PM


All times are GMT +1. The time now is 09:36 PM.

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

About Us

"It's about Microsoft Excel"