If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Disabling security using Thisworkbook in VBA

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-12, 19:47
Orton Orton is offline
Registered User
 
Join Date: Nov 2011
Posts: 4
Disabling security using Thisworkbook in VBA

Hi

I use 'workbook_open' and 'beforesave' functions in "Thisworkbook" module both to force save format at xlsm and also to check for the presence of a security device (keylok).

The probem is I've discovered by chance that "Thisworkbook" can be effectively disabled by opening and saving a workbook with the following "Thisworkbook" function:

PHP Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As BooleanCancel As Boolean)
Application.EnableEvents False
Application
.DisplayAlerts False
ActiveWorkbook
.Close True
End Sub 
The issue seems to be something to do with the loop created by saving within the beforesave function. My question is whether I can prevent such a function being used to disable the beforesave etc functions within my workbooks?

Any advice would be gratefully received.
Reply With Quote
  #2 (permalink)  
Old 01-14-12, 06:42
Orton Orton is offline
Registered User
 
Join Date: Nov 2011
Posts: 4
Application.Enableevents = true

Ive managed to find the answer. If you don't want "thisworkbook" to be disabled by a function in another workbook which sets application.enableevents = false, insert the following in a macro module of the workbook you want to protect:


PHP Code:
Private Sub Auto_Open()
    
Application.EnableEvents True
End Sub 
I am using this with the following "thisworkbook" function to prevent saving in anything other than the original format (in my case xlsm); I'm doing this is I understand xlsm is a more secure format than say xls - especially if workbook protection is used:

PHP Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As BooleanCancel As Boolean)
Application.EnableEvents False
Application
.DisplayAlerts False
ChDir 
"C:\******\"
ActiveWorkbook.Save
Application.EnableEvents = True
Application.EnableCancelKey = xlDisabled
ActiveWorkbook.Close False
End Sub 
Previously I could effectively disbable this function using the function in my original post attached to another workbook - and then opening in the same window.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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