Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Adding validation fails with automation error


You missed a dot in front of Range...
Set rMyRange = .Range(.Cells(4, 2), .Cells(10, 2))
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




wrote in message
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
-snip-
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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Adding validation fails with automation error

Thanks for your suggestion - I hadn't thought of doing that. It
doesn't fix it, though - still get the same error with a dot in front
of Range.

Philip.

On Feb 12, 1:26 pm, "Jim Cone" wrote:
You missed a dot in front of Range...
Set rMyRange = .Range(.Cells(4, 2), .Cells(10, 2))
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Adding validation fails with automation error

Phillip,
My guess is that you have other unqualified objects in your code.
The KB you referenced is not devoted to clarity but does provide
clues to most of the Excel automation problems posted in this group.

Do you have object references to...
Excel
The Workbook
The Sheet
The Validation object

Do you Set all objects to Nothing before exiting your code?
Are they set to Nothing in child to parent order?
After exiting your code, have you checked Task Manager to see if
an instance of Excel remains?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Philip"
wrote in message
Thanks for your suggestion - I hadn't thought of doing that. It
doesn't fix it, though - still get the same error with a dot in front
of Range.
Philip.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Adding validation fails with automation error

I think I have the fix. The problem is that adding validation to a
range fails if there are no cells selected on the worksheet (I
think). Sometimes this code was being called from a command button
click, and the button took the focus away from the underlying sheet,
meaning that adding the validation failed.

I haven't seen any documentation on when you can add validation to a
range, but this poster below ran into the same issue.

http://www.mcse.ms/message734048.html

Philip.

On Feb 12, 4:10 pm, "Jim Cone" wrote:
Phillip,
My guess is that you have other unqualified objects in your code.
The KB you referenced is not devoted to clarity but does provide
clues to most of the Excel automation problems posted in this group.

Do you have object references to...
Excel
The Workbook
The Sheet
The Validation object

Do you Set all objects to Nothing before exiting your code?
Are they set to Nothing in child to parent order?
After exiting your code, have you checked Task Manager to see if
an instance of Excel remains?
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automation error with XLA addin, fails on commandbarbutton onaction [email protected] Excel Programming 0 August 13th 07 07:14 AM
Adding Validation When Source Validates To Error? (PeteCresswell) Excel Programming 4 July 7th 07 10:55 PM
Validation fails on copying x6v87qe Excel Discussion (Misc queries) 3 May 8th 07 09:10 AM
VBA Inserted Data Validation Fails _RickK Excel Programming 3 January 24th 07 05:18 PM
Excel fails to open workbook using Automation from VB 6 Lowell Excel Programming 0 September 8th 05 05:33 AM


All times are GMT +1. The time now is 07:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"