Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
Try
SET fso = CreateObject("Scripting.FileSystemObject")
Object assignment needs the SET operator
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.
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.
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")
Have you tried changing the security settings in the macro dialog to Allow system Access?
Or are you trying to achieve this outside QV?
yes the script runs with Allowing system Access
I have tried without msgBox, but it also doesn't work
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.
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!