PC Review


Reply
Thread Tools Rate Thread

Automation of worksheet protection from Access VBA - can't insertrows afterwards

 
 
Mangetout
Guest
Posts: n/a
 
      2nd Jul 2009
I'm working on an access application that uses Excel and Outlook
automation to send spreadsheets by email,

Everything works, except that the sheets need their first 13 rows
protected (the header data), but need to permit the user to enter data
and insert rows into the detail part from the 14th row onward.

Starting with a completely unlocked, unprotected sheet, my code looks
like this:

'mark the cells locked:
objActiveWkb.Worksheets(1).Range("A1:Q13").Locked = True
objActiveWkb.Worksheets(1).Range("A1:Q13").FormulaHidden = False
'protect the sheet
'objActiveWkb.Worksheets(1).Protect ("MyPasswordHere"), DrawingObjects
= False, Scenarios = False, AllowInsertingRows = True,
AllowDeletingRows = True

I end up with a spreadsheet in which I can enter data into the detail
section (but not the first 13 rows, as desired), but I can's insert a
row anywhere in the sheet, even in the supposedly unprotected detail
section after row 14.

If I apply the protection manually, checking the Allow Deleting Rows
checkbox on the way, it works exactly as expected (but obviously I
can't expect the user to do this for the 200 spreadsheets the
application will send out each month).

What am I doing wrong?
 
Reply With Quote
 
 
 
 
Mangetout
Guest
Posts: n/a
 
      6th Jul 2009
On Jul 2, 4:18*pm, Mangetout <themanget...@hotmail.com> wrote:
> I'm working on an access application that uses Excel and Outlook
> automation to send spreadsheets by email,
>
> Everything works, except that the sheets need their first 13 rows
> protected (the header data), but need to permit the user to enter data
> and insert rows into the detail part from the 14th row onward.
>
> Starting with a completely unlocked, unprotected sheet, my code looks
> like this:
>
> 'mark the cells locked:
> objActiveWkb.Worksheets(1).Range("A1:Q13").Locked = True
> objActiveWkb.Worksheets(1).Range("A1:Q13").FormulaHidden = False
> 'protect the sheet
> 'objActiveWkb.Worksheets(1).Protect ("MyPasswordHere"), DrawingObjects
> = False, Scenarios = False, AllowInsertingRows = True,
> AllowDeletingRows = True
>
> I end up with a spreadsheet in which I can enter data into the detail
> section (but not the first 13 rows, as desired), but I can's insert a
> row anywhere in the sheet, even in the supposedly unprotected detail
> section after row 14.
>
> If I apply the protection manually, checking the Allow Deleting Rows
> checkbox on the way, it works exactly as expected (but obviously I
> can't expect the user to do this for the 200 spreadsheets the
> application will send out each month).
>
> What am I doing wrong?


Worked it out myself in the end - it needs to be either:
objActiveWkb.Worksheets(1).Protect Password :="MyPasswordHere",
DrawingObjects :=False, Scenarios := False, AllowInsertingRows := True

Or:
objActiveWkb.Worksheets(1).Protect "MyPaswordHere", ,
True, , , , , , , True, , , True
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access automation leaves Excel open which in turn locks 2nd automation attempts EagleOne@discussions.microsoft.com Microsoft Access 8 30th Jun 2008 01:27 AM
Access XL automation: where in VBA to Dim wks as Worksheet EagleOne@microsoftdiscussiongroups Microsoft Access 4 10th Jun 2008 12:17 AM
Detecting automation of my application (bot-protection) docholiday@lafrontera.de Microsoft C# .NET 3 20th Mar 2008 01:06 AM
Using Access Excel Automation, can I delete or rename a worksheet Stapes Microsoft Access 1 13th Sep 2007 12:07 PM
Worksheet protection is gone and only wokbook protection can be se =?Utf-8?B?RXJpYyBDLg==?= Microsoft Excel Misc 4 2nd May 2006 04:50 PM


Features
 

Advertising
 

Newsgroups
 


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