Solved

Excel 2007 VBA prevent workbook use with macros disabled

Posted on 2012-03-23
6
317 Views
Last Modified: 2012-06-18
Does anyone have any good ideas to stop use of a workbook when macros are disabled? I have some code in the Worksheet_Change and WorkSheet_SelectionChange that stops users inadvertently changing certain things.  I can't use protection for this some data is in a table and if the cells are protected the users can't sort and filter.

If they disable macros when the worbook opens they'll be able to change everything.  I thought of something like making the key sheets hidden and only unhiding them in Workbook_Open code, then hiding again when they close.  But if they start up, do some work, save, do some more work then close without saving changes, the sheets won't be hidden next time they open.

This does not need to be high security - it's just to stop accidental changes.  Any ideas?
0
Comment
Question by:andrewssd3
  • 4
  • 2
6 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37756575
This is the usual method: http://www.vbaexpress.com/kb/getarticle.php?kb_id=379
Essentially, every time you save, the sheets get hidden, the save is done, then the sheets get shown again. That way, the last save was always done with hidden sheets.
0
 
LVL 17

Author Comment

by:andrewssd3
ID: 37756610
Thanks Rory I'll give that a try.  I do have some issues with Worksheet_BeforeSave in my corporate environment (see this question which you participated in), but hopefully I'll be able to get this work.  I'll report back.
0
 
LVL 17

Author Comment

by:andrewssd3
ID: 37757235
Unfortunately, as I thought, it's not possible to change the visibility of worksheets from a Worksheet_BeforeSave routine that is initiated from VBA code (see the previous question I referred to).

Any other approaches to this that don't involve BeforeSave? Otherwise I'll award the points to you Rory as your solution would work well in a 'normal' environment.  Mine is skewed by having a document managment system that intercepts all Save and Open calls (the approach works when I disble the doc management add-in, but this is not an option for normal use).
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37757347
Could you use the beforesave to schedule a routine with OnTime to do the hide, save and reshow? Might work...
0
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 0 total points
ID: 37757587
Interesting idea - I'll give it a try...
0
 
LVL 17

Author Closing Comment

by:andrewssd3
ID: 38094558
Thanks for the input on this - it gave me some interesting avenues to try, but I could not get anything to work as I wanted.  In the end I just had to take the risk that some savvy user would be able to get round the macro issue.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question