Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all.
In this example we have a macro subroutine to delete all gauges.
The subroutine goes well, but sometime doesn't go.
I suppose it will be a time-out problem, but the question is:
there is another way to delete (close) all gauges with one command like in interactive mode?
When you delete an object and you have some other linked objects, the system ask you if you want to delete all objects or only selected.
There is a parameter to delete (close) all by macro?
For example:
objIndicators(i).close all
objIndicators(i).close true
...
Hi Corrado,
why do you delete gauges in two different way?
Regards
Han
Hi Han,
if you look at the API on Close member you find for SheetObject and Container this example:
rem ** remove all sheet objects on sheet Main **
set s=ActiveDocument.Sheets("Main")
orignumber=s.NoOfSheetObjects
for i=0 to orignumber-1
s.SheetObjects(0).Close
next
But if you try to find and close the object inside the container this example doesn't go.
Now I have some object (in my case some gauges) in a container and I need to close them.
I have found this way:
function IndicatorContainerDestroy (sContainer)
set objContainer = ActiveDocument.GetSheetObject(sContainer)
pContainer = objContainer.GetProperties
for i = 0 to pContainer.ContainedObjects.Count -1
sGaugeName = pContainer.ContainedObjects.Item(i).Def.ObjectId
set objGauge = ActiveDocument.GetSheetObject(sGaugeName)
objGauge.close
next
end function
Regards
Corrado.
Hi Corrado,
If You have just two linked gauges why don't you use this loop?
function IndicatorSheetDestroy (sSheetName)
set objSheet = ActiveDocument.Sheets(sSheetName)
objIndicators = objSheet.GetSheetObjects
for j = 1 to 2
for i = lBound(objIndicators) To uBound(objIndicators)
id = objIndicators(i).GetObjectId
ty = objIndicators(i).GetObjectType
if ty = 22 then
set objGauge = ActiveDocument.GetSheetObject(id)
objGauge.close
'objIndicators(i).close
end if
next
next
end function
Reguards
Han
Hi Han,
I have tested your suggestion and I have to note that:
the main loop looks always the gauges in the same sheet, but
why the first close command delete the gauge in the container?
Why if I put the "j" loop as internal it delete just one gauge in container an then the loop stops itself?
The "j" loop as internal:
function IndicatorSheetDestroyIntenalLoop (sSheetName)
set objSheet = ActiveDocument.Sheets(sSheetName)
objIndicators = objSheet.GetSheetObjects
for i = lBound(objIndicators) To uBound(objIndicators)
id = objIndicators(i).GetObjectId
ty = objIndicators(i).GetObjectType
if ty = 22 then
for j = 1 to 2
set objGauge = ActiveDocument.GetSheetObject(id)
'objIndicators(i).close
objGauge.close
next
end if
next
end function
Thanks in advance
Corrado.
Hi Corrado,
nice question!
I've tested the function too, it seems there is a stack lifo and close command delete the last in!
Another question:
If You want to choose which one to delete?
And then:
How many object there are in any stack?
I hope that some other can answer at these questions or add some information about how to manage linked objects by macro vb.
Han.
Hi Han,
look at the image below:
In caption of chart property you can see the number of linked objects!
May be it's an SheetObject property.
Corrado.