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

Disallow copy/clone for objects in a sheet

HI All,

The below is the Macro which I copied from API Guide to disable the Clone/Copy Option in the List Box .

'rem ** Disallow copy/clone for list box **



set LB = ActiveDocument.GetSheetObject("LB06")
set boxprop=LB.GetProperties
boxprop.Layout.Frame.AllowCopyClone = false
LB.SetProperties boxprop

Using the above as a reference any one please guide me with a macro that how to disable the Copy/Clone option in every object in a sheet and this has to be applied in all the sheets in a qlikview application .

Thanks in Advance ....

Regards,

Chakravarthy.



10 Replies
Not applicable
Author

you can loop through all the sheets in document and then loop through all the objects in the sheet and access the properties there. As shown in the sample code below: You may need to process each object type because it may have a different way of accessing the clonecopy property as shown by the "Button".

Also, you can also do Edit->Activate All and then Object->Property to change Allow Copy/Clone property in group. Just in case you want it done without using a macro.

Public Sub DeactivateCloneCopy
iNumSheets = ActiveDocument.NoOfSheets

for iCtr = 0 to iNumSheets - 1
objObjects = ActiveDocument.Sheets(iCtr).GetSheetObjects

for iObjCtr = lbound(objObjects) to ubound(objObjects)
Set prop = objObjects(iObjCtr).GetProperties
iObjectType = objObjects(iObjCtr).GetObjectType

'Button
if iObjectType = 5 then
prop.Frame.AllowCopyClone = False
objObjects(iObjCtr).SetProperties prop
elseif iObjectType = 11 then

else
prop.Layout.Frame.AllowCopyClone = False
objObjects(iObjCtr).SetProperties prop

end if
next
next
End Sub

I hope this helps.

Not applicable
Author

Dear Pinongs,

Thanks for your quick reply .

When I tried to execute this its displaying the following error

Object doesn't support this property or method: 'prop.Layout'

and also can you please explain the following part of Macro . As I am not so good in macros I could not understand the below code .

if iObjectType = 5 then

prop.Frame.AllowCopyClone = False

objObjects(iObjCtr).SetProperties prop







elseif iObjectType = 11 then

Thanks in Advance ..........

Regards,

Chakravarthy.







Not applicable
Author

Hi,

You may need to track the different type of objects in your sheets since not all of them have direct access to "AllowCopyClone" property. The if iObjectType = 5 in my sample code is checking whether the object being processed is a "Button" if this is the case the AllowCopyClone of button is under .Frame.AllowCopyClone. Another example would be StraightTableBox, to access its AllowCopyClone property, you need to access .GraphLayout.Frame (refer to the API guide for the other object type)

...

prop.GraphLayout.Frame.AllowCopyClone = False
objObjects(iObjCtr).SetProperties prop
....

You may opt to put the statement "objObjects(iObjCtr).SetProperties prop" after the last if else statement.

I hope this helps.

Not applicable
Author

Hi Pinongs,

Thanks for your reply .....

It solved my issue Smile

paulbridge
Contributor
Contributor

Hi

Whilst researching this issue for myself I came across some code which scans all objects across all sheets in a document and either enables or disables the 'move/size' and 'copy/clone' properties, which may be of use for other QlikView users. All credit for the code goes to Adriano W Almeida, who posted the solution on his blog (http://qlikman.blogspot.co.uk). I have added an additional check to the code to detect and set the properties for QlikView containers, as this object was not recognised in the original code.

To implement, call up the [Edit Module] script window (CRTL-M) and add the script below. Create a couple of buttons and assign the [Run Macro] action to each, with one button calling the [EnableMove] and the other calling [DisableMove].

Hope this is of use.

--------------------------------------

' Enable the move resize for all objects on the report.

sub EnableMove

' do the magic

setMove TRUE,TRUE

end sub

' Disable the move resize for all objects on the report.

sub DisableMove

' do the magic

setMove FALSE,FALSE

end sub

' Set the move properties to all objects

'msVal - Move/Size setting for non-chart objects

'chVal - Copy/Clone setting for non-chart objects

'amVal - Auto Minimize setting for chart objects

'ccVal - Move/Size setting for chart objects

function setMove (msVal, ccVal)

set doc = ActiveDocument

' for all the sheets set the property chosen

for j = 0 to ActiveDocument.NoOfSheets - 1

set s=ActiveDocument.GetSheet(j)

objs=s.GetSheetObjects

' for all objects

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

' get the object's name and property

set objInt = objs(i)

objID = replace(objInt.GetObjectId,"Document\","")

'msgbox("obj ID " & objID &" has the objType " & objs(i).GetObjectType)

set obj = doc.GetSheetObject(objID)

objProp = obj.GetProperties

' as each object has diferent places for the frame object, treat them differently

select Case objs(i).GetObjectType

Case 1,2,3,4,6,7,8,9,17,18,19,34,35 'LB,MB,SB,TB,TX,CS,IB,LA

objProp.Layout.Frame.AllowMoveSize = msVal

objProp.Layout.Frame.AllowCopyClone = ccVal

Case 5,31 'BU,SO

objProp.Frame.AllowMoveSize = msVal

Case 10,11,12,13,14,15,16,20,21,22,27,28 'CH's

objProp.GraphLayout.Frame.AllowMoveSize = msVal

objProp.GraphLayout.Frame.AllowCopyClone = ccVal

'objProp.GraphLayout.Frame.AutoMinimize = amVal

Case 36 'CT's

objProp.Frame.AllowMoveSize = msVal

objProp.Frame.AllowCopyClone = ccVal

Case Else

msgbox("ObjectID: " &objID & " with objectType: " & objs(i).GetObjectType &" couldn't be found, trying LB settings")

objProp.Layout.Frame.AllowMoveSize = msVal

objProp.Layout.Frame.AllowCopyClone = ccVal

end select

obj.SetProperties objProp

next

next

end function

--------------------------------------

Not applicable
Author

This one is short and sweet. You can create buttons that call "lockMoveSizeCopyClone" and "unlockMoveSizeCopyClone".

function unlockMoveSizeCopyClone()

{

    setMoveSizeCopyClone(true);

}

function lockMoveSizeCopyClone()

{

    setMoveSizeCopyClone(false);

}

function setMoveSizeCopyClone(boolAllow)

{

    var doc = ActiveDocument;

    for (var i = 0; i < doc.NoOfSheets(); i++)

    {

        var sheet = doc.Sheets(i);

        for (var j = 0; j < sheet.NoOfSheetObjects(); j++)

        {

            var sheetObject = sheet.SheetObjects(j);

            var frame = sheetObject.GetFrameDef();

            frame.AllowCopyClone = boolAllow;

            frame.AllowMoveSize = boolAllow;

            sheetObject.SetFrameDef(frame);

        }

    }

}

michaelfreitas
Creator
Creator

If you do not want / know how to use macros for the possibility to do manually:


Settings..Document Properties..Sheets. There are two lists on this tab.

1. At the top, you select all tabs, if you want the change to all objects of all tabs, or do not click anywhere, it's the same.

2. At the bottom, it shows all the application objects, you select all lines.

3. Click the Properties button, which is next to the Delete button.

4. In the window that opens, Layout tab, uncheck Allow Copy / Clone and any other option as you want.

5. Click OK .. OK again.

ready

kamal_sanguri
Specialist
Specialist

Hi Mike,

Thank you for such a wonderful trick... I was wasting my locking objects one by one..


Cheers,

Kamal

michaelfreitas
Creator
Creator

Hi Kamal!

Your welcome!