1 Reply Latest reply: Dec 20, 2012 9:06 AM by Dave Riley RSS

    Store OBJECTID in a variable

    Kumar M

      Hi All,

       

      In the enclosed sample file, I have few objects which need to be "send to excel with caption".
      We have the macro for the same which works fine for an object whose objectID is hardcoded in the macro.

       

      The requirement is I need to pass the OBJECTID of the selected chart (one at a time) to the macro through a variable.

      Appreciate if someone suggest how do we achieve this?

       

      Thanks,

      Kumar

        • Re: Store OBJECTID in a variable
          Dave Riley

          The following code will iterate over every object on a sheet and tell you which objects are active BUT the problem is when you click a button to trigger the macro, the button becomes the sole active object!!

           

          objs=s.GetSheetObjects

          for i=lbound(objs) to ubound(objs)

              if objs(i).IsActive then msgbox objs(i).getObjectId & " is active"

          next

           

          ... not sure if assigning the macros to the menu bar (Macro 1, Macro 2, Macro 3) would fix this, but you also have the issue if multiple objects are selected.

           

          Perhaps you could place all your charts into a container and use the following to identify the chosen chart ...

           

          set ContainerObj = ActiveDocument.GetSheetObject("CT01")

              Set ContProp = ContainerObj.GetProperties

          ActiveObject=ContProp.SingleObjectActiveIndex

          msgbox "Active Object=" & ActiveObject & "  Id=" & ContProp.ContainedObjects.Item(ActiveObject).text.v

           

          The example in APIGuide shows it should be possible to identify the ActiveObject Id (ContProp.ContainedObjects.Item(0).Id) but this doesn't work in QV11 it seems, you might need to put the actual object ID via the container properties object labels (Objects Displayed in Container).

           

          flipside