Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Assigning Selection Color in Macro with value from Script

I want to change the selection colors in one Qlikview application where I have the possibility to define the colors in the load script. When I define the selection color directly in the Macro, everything works well. The macro looks like follows:

MACRO:

Sub SetColorPrefs()

     dim UserPrefs

     set UserPrefs = ActiveDocument.GetApplication.GetUserPreferences

     UserPrefs.CustomSelBgColor(1).PrimaryCol.Col = RGB(255,0,0)

     ActiveDocument.GetApplication.SetUserPreferences UserPrefs

End Sub

I then tried to put the RGB setting in the loadscript in a variable and to refer to the variable in the macro. Unfortunately the macro does not accept this.

LOAD SCRIPT:

set vColor = RGB(255,0,0);

MACRO:

Sub SetColorPrefs()

     dim UserPrefs

     set User Prefs = ActiveDocument.GetApplication.GetUserPreferences

     UserPrefs.CustomSelBgColor(1).PrimaryCol.Col = ActiveDocument.Variables("vColor").GetContent.String

     ActiveDocument.GetApplication.SetUserPreferences UserPrefs

End Sub

My Overall target is to define the Color Settings in the load script or even in an external file which users can modify easily.

Does anyone have an idea how I can make this work?

Thanks a lot in advance for your help

2 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

This is not a per document setting. The macro changes the user preferences in the setting.ini file somewhere down in the users AppData folder. If your users access the document via Qlikview Server then this setting won't work unless you put it into the settings.ini file on the server. Note that the changed setting will apply to all users for all documents on your Qlikview Server.


You could try modifying this extension to do what you want: Document Extension to override green selection color


talk is cheap, supply exceeds demand
jhamard
Partner - Contributor III
Partner - Contributor III

Hi,

In fact RGB() is a VBS function that return a number : https://www.w3schools.com/asp/func_rgb.asp


>> UserPrefs.CustomSelBgColor(1).PrimaryCol.Co is waiting for a number !

The solution is prety simple in fact. Use the Eval() function to "evaluate" the result of your RGB(255,0,0) string : https://www.w3schools.com/asp/func_eval.asp

Sub SetColorPrefs()

    dim UserPrefs

    set User Prefs = ActiveDocument.GetApplication.GetUserPreferences

    UserPrefs.CustomSelBgColor(1).PrimaryCol.Col = Eval(ActiveDocument.Variables("vColor").GetContent.String)

    ActiveDocument.GetApplication.SetUserPreferences UserPrefs

End Sub

It works perfectly for me