Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
phaneendra_kunc
Partner - Specialist III
Partner - Specialist III

Macro to Export Variables to CSV

I ma trying to use a macro in my application that will exports the variables from a second application to CSV format..

I am using below code and it is not working....any help would be greatly appritiated..!!!

Sub MainProcess

set App=ActiveDocument.GetApplication

docpath = ActiveDocument.GetVariable("QVW").GetContent.String

Set docObj = App.OpenDoc (docpath,"","")

Call extractVars(docObj)

End Sub

sub extractVars(docObj)

'vExportTo = doc.Variables("vExportTo").GetContent.String

outputDir = "C:\Documents and Settings\XXX\Desktop\Field Usage\Delete\"

    Set objTextFile = openOutputFile(outputDir & "variables.csv")

   

    objTextFile.WriteLine("VariableName,VariableValue,RawVariableValue")

    Set vars = docObj.GetVariableDescriptions

   

    for i = 0 to vars.Count - 1

        set v = vars.Item(i)      

        If Not (v.IsReserved Or v.IsConfig) Then

            shownValue = v.ShownValue.String

            ' On Error Resume Next

            objTextFile.WriteLine( _

                csvQuote(v.Name) _

                & "," & csvQuote(docObj.GetVariable(v.Name).GetContent.String) _

                & "," & csvQuote(v.RawValue) _

            )     

        End If     

    next   

objTextFile.Close()

UserFile.CloseDoc

end sub   

 

Function openOutputFile(filename)

Rem *** Create and open an output file

    CONST ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set openOutputFile = objFSO.OpenTextFile (filename, ForWriting, True)

End Function

1 Solution

Accepted Solutions
phaneendra_kunc
Partner - Specialist III
Partner - Specialist III
Author

It is working now....

I have missed some parameters...

CONST QUOTE = """"

Sub MainProcess

set App=ActiveDocument.GetApplication

docpath = ActiveDocument.GetVariable("QVW").GetContent.String

Set docObj = App.OpenDoc (docpath,"","")  ' Open the document

    Call extractVars(docObj)

docObj.CloseDoc

ActiveDocument.Reload()

End Sub

Sub extractVars (docObj)

    outputDir = ActiveDocument.Variables("vPrjLoc").GetContent.String   

    Set objTextFile = openOutputFile(outputDir & "\variables.csv")

    objTextFile.WriteLine("VariableName,VariableValue,RawVariableValue")

    Set vars = docObj.GetVariableDescriptions

    for i = 0 to vars.Count - 1

        set v = vars.Item(i)

        rem exclude IsConfig & IsReserved vars

        If Not (v.IsReserved Or v.IsConfig) Then

            shownValue = v.ShownValue.String

            objTextFile.WriteLine( _

                csvQuote(v.Name) _

                & "," & csvQuote(docObj.GetVariable(v.Name).GetContent.String) _               

                & "," & csvQuote(v.RawValue) _

            )

        End If

    next

    objTextFile.Close()

End Sub

 

Function openOutputFile(filename)

Rem *** Create and open an output file

    CONST ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set openOutputFile = objFSO.OpenTextFile (filename, ForWriting, True)

End Function

Function csvQuote(str)

    csvQuote = QUOTE & replace(str, """", """""")    & QUOTE

End Function

View solution in original post

2 Replies
phaneendra_kunc
Partner - Specialist III
Partner - Specialist III
Author

It is working now....

I have missed some parameters...

CONST QUOTE = """"

Sub MainProcess

set App=ActiveDocument.GetApplication

docpath = ActiveDocument.GetVariable("QVW").GetContent.String

Set docObj = App.OpenDoc (docpath,"","")  ' Open the document

    Call extractVars(docObj)

docObj.CloseDoc

ActiveDocument.Reload()

End Sub

Sub extractVars (docObj)

    outputDir = ActiveDocument.Variables("vPrjLoc").GetContent.String   

    Set objTextFile = openOutputFile(outputDir & "\variables.csv")

    objTextFile.WriteLine("VariableName,VariableValue,RawVariableValue")

    Set vars = docObj.GetVariableDescriptions

    for i = 0 to vars.Count - 1

        set v = vars.Item(i)

        rem exclude IsConfig & IsReserved vars

        If Not (v.IsReserved Or v.IsConfig) Then

            shownValue = v.ShownValue.String

            objTextFile.WriteLine( _

                csvQuote(v.Name) _

                & "," & csvQuote(docObj.GetVariable(v.Name).GetContent.String) _               

                & "," & csvQuote(v.RawValue) _

            )

        End If

    next

    objTextFile.Close()

End Sub

 

Function openOutputFile(filename)

Rem *** Create and open an output file

    CONST ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set openOutputFile = objFSO.OpenTextFile (filename, ForWriting, True)

End Function

Function csvQuote(str)

    csvQuote = QUOTE & replace(str, """", """""")    & QUOTE

End Function

bluecarbon
Partner - Creator
Partner - Creator

Hi,

Can you help me to differentiate what is ShownValue and Raw value in the above code with an example?

Thanks,

Rakul.