Connecting Tech Pros Worldwide Help | Site Map

Excel protect sheet macro problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 07:18 AM
Giganews
Guest
 
Posts: n/a
Default Excel protect sheet macro problem

I have an Access 97 database in which I am running an Excel macro through
automation. The macro in Excel is as follows:

Worksheets("Sheet1").Protect Password:="****", DrawingObjects:=True,
Contents:=True, Scenarios:=True

When I call this macro from the database all works fine except when I
recorded the macro I deselected the "Select locked cells" option under the
"Allow all users of this worksheet to:" section but yet when I access the
worksheet I can still select a locked cell. I get a message when I do so
letting me know it is locked but I don't want the user to be able to select
locked cells.

The macro is run in a new copy of the spreadsheet every time it runs due to
a filecopy command in the database. Could this be causing the problem?

I tried using the following code in the macro:
Worksheets("Sheet1").EnableSelection = xlUnlockedCells but once the
spreadsheet is closed this code has no affect. Adding this code to the on
open event of the spreadsheet is not an option due to the users that will be
receiving this spreadsheet are told to not enable macros on all
spreadsheets. Company policy!

Does anyone have a suggestion? Is there a parameter that I can add to my
protect macro?

Any help would be greatly appreciated.



  #2  
Old November 13th, 2005, 07:19 AM
John Nurick
Guest
 
Posts: n/a
Default Re: Excel protect sheet macro problem

You need to call Worksheet.EnableSelection before you protect the sheet.

IOW you have to

On Thu, 10 Feb 2005 23:40:44 -0500, "Giganews" <hereinde@yahoo.com>
wrote:
[color=blue]
>I have an Access 97 database in which I am running an Excel macro through
>automation. The macro in Excel is as follows:
>
>Worksheets("Sheet1").Protect Password:="****", DrawingObjects:=True,
>Contents:=True, Scenarios:=True
>
>When I call this macro from the database all works fine except when I
>recorded the macro I deselected the "Select locked cells" option under the
>"Allow all users of this worksheet to:" section but yet when I access the
>worksheet I can still select a locked cell. I get a message when I do so
>letting me know it is locked but I don't want the user to be able to select
>locked cells.
>
>The macro is run in a new copy of the spreadsheet every time it runs due to
>a filecopy command in the database. Could this be causing the problem?
>
>I tried using the following code in the macro:
>Worksheets("Sheet1").EnableSelection = xlUnlockedCells but once the
>spreadsheet is closed this code has no affect. Adding this code to the on
>open event of the spreadsheet is not an option due to the users that will be
>receiving this spreadsheet are told to not enable macros on all
>spreadsheets. Company policy!
>
>Does anyone have a suggestion? Is there a parameter that I can add to my
>protect macro?
>
>Any help would be greatly appreciated.
>[/color]

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.