
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- fso = CreateObject("Scripting.FileSystemObject")
- 'msgbox ("FSO: " & fso)
- 'dateipfad = "path_and_name.txt"
- 'fsoFile = fso.opentextfile(dateipfad, fsoForReading)
- 'inhalt = Split(fsoFile.ReadAll, vbCr)
- 'inhalt = fsoFile.ReadAll
- 'msgBox(inhalt)
- 'fsoFile.Close
- 'fsoFile = Nothing
- Tags:
- vbamacro
- « Previous Replies
-
- 1
- 2
- Next Replies »
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try
SET fso = CreateObject("Scripting.FileSystemObject")
Object assignment needs the SET operator

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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")

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried changing the security settings in the macro dialog to Allow system Access?
Or are you trying to achieve this outside QV?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes the script runs with Allowing system Access

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have tried without msgBox, but it also doesn't work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!

- « Previous Replies
-
- 1
- 2
- Next Replies »