View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] PhilipAppsWork@gmail.com is offline
external usenet poster
 
Posts: 1
Default Adding validation fails with automation error

I'm using Visual Basic 6.5 and Excel 2003 SP3. Here's some excerpts
from a sub:

Dim rMyRange As Range

With wksMyWorksheet ' name of a worksheet
Set rMyRange = Range(.Cells(4, 2), .Cells(10, 2))
End With

With rMyRange.Validation
.Delete
.Add Type:=Excel.xlValidateDecimal,
AlertStyle:=Excel.xlValidAlertStop, Operator:=Excel.xlGreaterEqual,
Formula1:="0"
.IgnoreBlank = False
.InCellDropdown = False
.ErrorTitle = "Error"
.ErrorMessage = "Must be = 0"
.ShowError = True
End With

When I run this, I sometimes get, when adding the validation: Run-time
error '-2147417848 (80010108' : Method 'Add' of object 'Validation'
failed. Sometimes it says "Automation error. The object invoked has
disconnected from its clients".

The workaround I have is to do:
rMyRange.Select
With Selection.Validation
...
End With

instead, which cures the problem, but I don't see why this should be
necessary or why the original code fails. The Microsoft page
http://support.microsoft.com/default...;en-us;Q319832 is not
enlightening.

Any ideas?

Thanks in advance,
Philip.