Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
How can I delete a table box from macro?
Thank's a lot!!
Pol
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
This will give you some ideas. You can aject always check object properties (for a name, id, etc) before you remoe it. Have fun playing with it.
I am looking for a way to delete just one tablebox from a sheet. I know the object id and will delete it by name.
I have tried the above code that is the same as the API Guide and it does not work in 9.0. If I have three objects on the sheet, it will delete two of them. If there is only one tablebox on the sheet it will not be deleted. I cannot get it to delete all the objects, it always leaves one object. Anyway, I really only want to delete one object.
I have run into a couple of times where code from the API guide does not work in 9.0. Does anyone use the "SheetObjects(0).close" function above.
Thanks,
JS
Figured out my own issue. The macro from the API does work, but not if you create the objects and specify a ObjectId with a macro. That is a different story. Here is the code I use to delete just one object with a given name:
set s=ActiveDocument.Sheets("Testing")
orignumber=s.NoOfSheetObjects
for i=0 to orignumber-1
rem ** get unique object ID for given object on sheet **
set so = s.SheetObjects(i)
id = so.GetObjectId
msgbox("ID = " & id)
IF id = "Document\TempTable" THEN 'TableBox to be deleted
s.SheetObjects(i).Close
END IF
next
Hope this helps the next guy.
Thanks,
JS