Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

read the input of a .txt file into a variable in my vba macro script

Hi @All,

i want to read the input of a .txt file into a variable in my vba macro script.

In line 2 the fso Object is empty ? I don't know why ? So the rest of my script can' work, because i need the fso Object

  1. fso = CreateObject("Scripting.FileSystemObject")
  2. 'msgbox ("FSO: " & fso)
  3. 'dateipfad = "path_and_name.txt"
  4. 'fsoFile = fso.opentextfile(dateipfad, fsoForReading)
  5. 'inhalt = Split(fsoFile.ReadAll, vbCr)
  6. 'inhalt = fsoFile.ReadAll
  7. 'msgBox(inhalt)
  8. 'fsoFile.Close
  9. 'fsoFile = Nothing
Tags (1)
1 Solution

Accepted Solutions
Not applicable

Re: read the input of a .txt file into a variable in my vba macro script

Ok thanks, i have the solution.

So I didn't knew that there are a difference between VBA and VBScript.

Like Mr. Zeeman explains, the QlikView Macro only supports VBScript.

So in the past i had VBA Commands in my code, and so it doesn't function.

Here my solution

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)

Do Until objFile.AtEndOfStream

    strSearchString = objFile.ReadLine

Loop

objFile.Close

10 Replies
Not applicable

Re: read the input of a .txt file into a variable in my vba macro script

Try

SET fso = CreateObject("Scripting.FileSystemObject")

Object assignment needs the SET operator

Not applicable

Re: read the input of a .txt file into a variable in my vba macro script

I have set the Set operator before, but it also doesn't work.

I'm testing it at the moment wit the set operator, but it also doesnt' work.

MVP
MVP

Re: read the input of a .txt file into a variable in my vba macro script

Creating object is like creating a placeholder. Unless it holds something magbox would not probably be able to show that. Try without those message boxes.

Not applicable

Re: read the input of a .txt file into a variable in my vba macro script

Alternatively, you can read the file in the Qlikview LOAD script in stead of in a macro.

If you do need the value in a macro you can access the script variable like this

set MyVar = ActiveDocument.Variables("vName")

jerrysvensson
Valued Contributor II

Re: read the input of a .txt file into a variable in my vba macro script

Have you tried changing the security settings in the macro dialog to Allow system Access?
Or are you trying to achieve this outside QV?

Not applicable

Re: read the input of a .txt file into a variable in my vba macro script


yes the script runs with Allowing system Access

Not applicable

Re: read the input of a .txt file into a variable in my vba macro script

I have tried without msgBox, but it also doesn't work

Not applicable

Re: read the input of a .txt file into a variable in my vba macro script

Do you have maybe an example or tutorial, where i can read a txt file into a variable in vba macro of qlikview. Because i have the experience, that the vba macro is not the same as the "normal" vba language.

Not applicable

Re: Re: read the input of a .txt file into a variable in my vba macro script

First in your LOAD script read the file and assign the value to a variable (I assume the file has just 1 value)

LOAD @1

FROM

C:\Temp\myvar.txt

(txt, codepage is 1252, no labels, delimiter is '\t', msq);

Let vVar = Peek('@1', -1);

Next, in your VBScript macro you can read the Qlikview variable:

Function GetVar

  set MyVar = ActiveDocument.Variables("vVar")

  'add your stuff here

End Function

Remember to always see if you really need a macro, you'd be amazed what you can accomplish with the - more robust and manageable - Qlikview load script.

By the way

the vba macro is not the same as the "normal" vba language.

Qlikview does not use VBA, it is VBScript. A small but essential difference!

Community Browser