Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
rakesh_kumar
Creator
Creator

QlikView Macro to delete all objects below a line. Macro logic should be based on Y-pos of the line

Hi Guys, I need help with a QlikView macro that deletes all objects below a line as in the screenshot below.  When the 'Delete Objects' button is clicked, a macro should run that deletes all the objects below the line. It should be dynamic, that means if there are any other tables or charts below this line they all should also be deleted aswell, so no hardcoding of object IDs should be used in the macro, the logic should be dynamic like delete all objects below the Y-pos = 168 (line position). Please find the example qvw file attached

 

Delete Objects Macro.jpg

Any help is greatly appreciated?

Thanks

Labels (4)
2 Replies
rakesh_kumar
Creator
Creator
Author

I tried using the below macro (Also please see this macro in the attached qvw):

Sub DeleteObjectsNew
	set s=ActiveDocument.ActiveSheet
	orignumber=s.NoOfSheetObjects
	
	for i=0 to orignumber-1
		set obj = s.SheetObjects(i)
		pos = obj.GetRect.Top
		 if ( pos > 168) then
	     		s.SheetObjects(i).Close
		 end if
	next	
End SUB

But this is not working as expected. When I clicked the Delete Objects button, its opening the macro editor, which when I closed shows that some objects were deleted. I had to repeat this a few times to get all the objects deleted. 

Any thoughts on how to tweak this code to make it work correctly?

 

Thanks

Brett_Bleess
Former Employee
Former Employee

This is most likely a timing issue, look at the WaitForIdle API, if you put that between each loop, it may work consistently, I believe the underlying issue is the calculation engine and the API fighting over things, the API I mentioned will pause things allowing the Calc engine to recalc before the next iteration occurs, will likely slow things down too, just FYI, but if I am correct, it should get things to run all the way through I believe.  

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.