Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I am running QV9sr4 and have a document that creates list boxes through a macro and then tries to make one of them active. However the object isnt found. The attached example shows the problem:
- Click the 'Add' button to automatically create 3 list boxes, WaitForIdle then save
- Now click any of the Activate buttons and the macro will fail (object not found)
However, close QV (no save required) and go back in an click any of the Activate buttons and all is fine. Ironically, where the 'activate' doesnt find the objects, they are seen by 'GetListBoxes' as can be seen if you click 'Remove'.
Any ideas how I can activate a listbox without the macro falling over?
Regards,
Gordon
That's a strange one. It seems it doesn't like your custom naming conventions. It worked for me when I changed the "OS1" in the code to the default "LB01". Weird.
It seems that you cannot reference it by Name (ID) or by SheetObject number (which incidentally I can't seem to find in the object properties anywhere - had to loop through all sheet objects to find out which Id mapped to which number)
An odd one indeed! I tried changing the IDs to the standard naming convention as LB101, LB102, LB103 which results in references to LB101 erroring but LB102 and LB103 being OK!
I'll report this to support and see what they say.
Regards,
Gordon
Gordon,
it looks like a bug, and I'd recommend reporting it... As a work around - take advantage of the fact that it's working with "GetSheetObjects" or "GetListBoxes" and go around the problem, like this:
sub activate11
Objects = ActiveDocument.ActiveSheet.GetSheetObjects
For i = lBound(Objects) To uBound(Objects)
If Objects(i).GetObjectID = "OS2" Then 'pivot tables
Objects(i).Activate
end if
next
end sub
Thanks Oleg,
I have reported it and in the meantime will use the workaround (with an 'exit for' added after the .activate to terminate the loop).
Gordon