ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Method 'Range' fails while using AllowEditRanges (https://www.excelbanter.com/excel-programming/417562-method-range-fails-while-using-alloweditranges.html)

Arkansas Lady

Method 'Range' fails while using AllowEditRanges
 
I am using Microsoft Access to create a worksheet and I'm having problems
with the code below. I have originally posted this to the Microsoft Access
discussion group and I haven't been able to get the results I need. The
first time I run this, it works correct. The second time I run it, I get a
run time error 1004 Method 'Range" of object '_Global' failed. If I run it a
third time, it works, a fourth time it fails, etc. I have run it first with
the title 'Time' and it works. Then I've changed the title before running it
the second time. But it still fails the second time. Each time I use the
same exact record to test with so it can not be my data. Can you help me?
Thank you

XLSheet.Unprotect
Dim aer As Object
For Each aer In XLSheet.Protection.AllowEditRanges
If aer.Title = "Time" Then
aer.Delete
Exit For
End If
Next
XLSheet.Protection.AllowEditRanges.Add Title:="Time", Range:=Range("$H$" &
Irow & ":$I$" & Mrow - 1)
XLSheet.Protect Password:="cpw1959", DrawingObjects:=True, Contents:=True,
Scenarios:=True

--
Arkansas Lady


All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com