Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I need to create a chart from xml properties file. Below code snippet will create chart but when try to assign object reference, i get "Macro parse failed functionality was lost"
ActiveDocument.Sheets(0).CreateObjectFromXmlPropertiesFile "C:\Qlikview\top10+discrepancies.xml" // this works
set chart1 = ActiveDocument.Sheets(0).CreateObjectFromXmlPropertiesFile "C:\Qlikview\top10+discrepancies.xml" //Macro parse failed
Please suggest any alternative way to achive above
Thanks in advance
Padmasali
As you've noted, CreateObjectFromXmlProperties file has no return value. From past testing, I've found that the new object is always added as the first object in the collection. I've never verified that this will always be true, but I've had success with:
ActiveDocument.ActiveSheet.CreateObjectFromXmlPropertiesFile "somefile"
sObjects = ActiveDocument.ActiveSheet.GetSheetObjects 'Objects this sheet
set newObj = sObjects(uBound(sObjects)) ' Get first obj in collection
-Rob
As you've noted, CreateObjectFromXmlProperties file has no return value. From past testing, I've found that the new object is always added as the first object in the collection. I've never verified that this will always be true, but I've had success with:
ActiveDocument.ActiveSheet.CreateObjectFromXmlPropertiesFile "somefile"
sObjects = ActiveDocument.ActiveSheet.GetSheetObjects 'Objects this sheet
set newObj = sObjects(uBound(sObjects)) ' Get first obj in collection
-Rob
Just to add to this, this doesn't seem to work if the objects are on different layers, uBound always seems to return the object on the topmost layer.
OK, found a reliable way to get the ID of the new sheet object, using a dictionary.
Before creating the new sheet object, create a dictionary with all the objects in the sheet:
' As we cannot get the ID for the newly copied sheet object, we need to keep
' track of all existing sheet objects and check for the new one
set objList = CreateObject("Scripting.Dictionary")
for each sht in sheet.GetSheetObjects
' Just in case there are linked objects in the same sheet
if not objList.exists(sht.GetObjectID) then objList.add sht.GetObjectID, 1
next
then after adding the object from the XML properties, run through all the sheet objects again, the one that isn't in the list is the new one:
' Check the dictionary to get the new sheet object
for each sht in sheet.GetSheetObjects
' If the object doesn't exist it must be the one we created
if not objList.exists(sht.GetObjectID) then
objList.Add sht.GetObjectID, 1
newObjId = sht.GetObjectID
end if
next
In this example, newObjId contains the ID of the new object.
Hi Rob,
How can we achieve the samething using Qlik OCX C# code.
I want to retrieve the object id of the newly added object.