Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
Peony
Contributor II

VBS. openOutputFile issue

Hi all.

Here is the macro to save variables from dashboard into particular .csv file.

Whan i run it as button-push action it opens "EditModule" window at the line: Set objTextFile = openOutputFile(fileName & ".var.csv"). Please help to understend what is wrong with code?

Sub extractVars

    fileName= replace(ActiveDocument.GetProperties.FileName,".qvw","")

    Set objTextFile = openOutputFile(fileName & ".var.csv")

    objTextFile.WriteLine("VariableName|VariableValue")

    Set vars = ActiveDocument.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(v.RawValue))

        End If

    next

    objTextFile.Close()

    msgbox("Vars saved:"&vars.Count)

End Sub

Tags (1)
1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: VBS. openOutputFile issue

You need to create a FileSystemObject for it. Here an example how it could be done: Re: Export to CSV with quotation marks.

- Marcus

View solution in original post

4 Replies
MVP & Luminary
MVP & Luminary

Re: VBS. openOutputFile issue

You need to create a FileSystemObject for it. Here an example how it could be done: Re: Export to CSV with quotation marks.

- Marcus

View solution in original post

Peony
Contributor II

Re: VBS. openOutputFile issue

Marcus, thank you for your advice. I've add it as:

Set fso = CreateObject("Scripting.FileSystemObject")

Set objTextFile = fso.openOutputFile(fileName & ".var.csv")

But the problem is still stay.

MVP & Luminary
MVP & Luminary

Re: VBS. openOutputFile issue

It should be:

Set objTextFile = fso.OpenTextFile(fileName & ".var.csv", 2, true)

To the meaning of the second/third parameter just put the keyword into google and you will find a lot of examples.

- Marcus

Peony
Contributor II

Re: VBS. openOutputFile issue

Thank you again. I made changes, so now macro is works Here it is:

Sub a1

dim fso, fileName, filePath, fileVar, vars, storageFile

fileName = replace(ActiveDocument.GetProperties.FileName,".qvw","")

filePath = (fileName)&".var.csv"

    Set fso = CreateObject("Scripting.FileSystemObject")

    If fso.FileExists(filePath) Then

        Set storageFile = fso.OpenTextFile (filePath, 2, True)

    Else

        Set storageFile = fso.CreateTextFile(filePath)

    End If

    Set vars = ActiveDocument.GetVariableDescriptions

    for i = 0 to vars.Count - 1

        set v = vars.Item(i)

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

        storageFile.WriteLine (v.Name & "|" & v.RawValue)

        End If

    next

    storageFile.Close()

    msgbox("Vars saved:"&vars.Count)

End Sub