Copy Variables from one QVW to another using a button click

Variable in qlikview is not just temporary storage while executing script. Indeed, variables will exist after the script execution is finished.


Variables provide lot of flexibility when you have to do calculations dynamically. Variables can be used in data transformations and Calculations.


This piece of code will helps to reuse the variable from one qlikview file to another. Hence, it reduces the time required to create variable individual in the new file.

Logic Used

1.       Getting file source and destination name through the input box using vb macro.

2.       Reading the variable from source file.

3.       Checking the progress using message box if needed.

4.       Creating new variable in the destination file along with the details.

5.       New button with macro name in actions.

Macro Used

Sub Copy_Variables ()

Dim objQV, objSource, objDest, objSourceVar, objDestVar
Dim objVars, varcontent, objTempVar, varname, i, varctr

fn_source=inputbox(“Enter source file path”,”Filename”)
if trim(fn_source)=”” then ‘no entry or cancel
exit sub
end if
Set objSource=Application.OpenDoc(fn_source)

fn_dest=inputbox(“Enter destination file path”,”Filename”)
if trim(fn_dest)=”” then
exit sub
end if
Set objDest=Application.OpenDoc(fn_dest)

set objVars=objSource.GetVariableDescriptions
for i = 0 to objVars.Count – 1
set objTempVar = objVars.Item(i)
Set objSourceVar=objSource.Variables(varname)

‘update the value of variable in destination document
Set objDestVar=objDest.Variables(varname)
If objDestVar is nothing then
‘must need to create variable
objDest.CreateVariable varname
Set objDestVar=objDest.Variables(varname)
End If

objDestVar.SetContent varcontent,true

x=msgbox(varctr&” variables copied from “&fn_source&” to “&fn_dest&”.”&chr(13)&”OK to Save?”,vbOKCancel,”Copy_Variables”)
if x=vbOK then
End if
set objSource=nothing
set objDest=nothing
set objVars=nothing
set objTempVar=nothing
set objSourceVar=nothing
set objDestVar=nothing
End Sub

By: Sivaraj Seeman

No Comments

Leave a Comment

Your email address will not be published.