2 Replies Latest reply: Feb 28, 2013 8:09 AM by Micael Leal RSS

    Delete Object VBS

      Hello,

       

      I created a table with some random Dimension and Expression

       

      Set Table = ActiveDocument.ActiveSheet.CreateStraightTable

      Table.AddDimension ("Title"&Suffix)

      Table.AddExpression ("[Current State"&Suffix&"]")

      .

      Now, when I want to use filters to order by some criteria, I want to rebuild everything the table like I did before, but with CreateStraightTable, it will generate again a new table and I want to drop the old table.

       

      I thought about doing :

       

      Set the_table = ActiveDocument.GetSheetObject("Table")         // Where Table is the name from my current Sheet.

       

      the_table.Cut

      or:

      the_table.Remove

      or:

      the_table.DeleteObject()

       

      But none of those are working.

       

      Could someone give me a hint?

       

      Thanks

        • Re: Delete Object VBS
          Gysbert Wassenaar

          You need to use the close() member:

           

          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

          • Re: Delete Object VBS

            Hello,

            Thanks for the quick reply.

            It deletes all Objects from the Sheet.

            But with a bit of adaptation I figured out the rest and this link:

             

            http://community.qlik.com/thread/3177

             

            'Delete Previous Chart

            rem ** remove one sheet object on sheet Main **

            set s=ActiveDocument.Sheets("Main")

            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

                 'Prints all objects ids on the current sheet

                 'msgbox("ID = " & id)

                 'Prints Table ID

                 IF id = "Document\Table" THEN

                     'TableBox to be deleted

                     s.SheetObjects(i).Close

                 END IF

            next