Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
j_nlucas
Partner - Contributor III
Partner - Contributor III

Macro fails when opening a file

Hi,

I am trying to read a txt file form a macro, but it's not working. The syntax seems to be right, and I have set the "requested module security" to "system access" and "Current Local Security" to "allow system access". And of course, I have made sure that the file is there and there is no a permissions problem. The code is really simple:

SUB mReadDelimitedFile()

   Set objFSO = CreateObject("Scripting.FileSystemObject") 

   msgbox 2

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

   msgbox 3

END SUB

well... it just doesn't execute msgbox 3.

Any idea?

Thank you.

1 Solution

Accepted Solutions
IAMDV
Master II
Master II

Hi Mate,

There is an issue using the constant for "ForReading in OpenTextFile method. You need to use the values "1" instead of the constant. So replace "ForReading" with "1". Here is the updated script:

SUB mReadDelimitedFile()

  Set objFSO = CreateObject("Scripting.FileSystemObject")

  msgbox 2

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

  msgbox 3

END SUB

Thanks,

DV


www.QlikShare.com

View solution in original post

7 Replies
IAMDV
Master II
Master II

Hi,

I guess it does execute "2" but doesn't execute "3". Do you mind posting the sample app?

Thanks,

DV

www.QlikShare.com

Not applicable

Are you trying to run it under ajax client ?

If so, macros struggle


j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

Hi Deepak,

That's right. It doesn't reach 3.

I just attached an example.

Thank you

Joaquin

j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

Hi Graeme,

No, that's still desktop!

Thanks


Not applicable

Sorry - I replied before you attached the qvw


IAMDV
Master II
Master II

Hi Mate,

There is an issue using the constant for "ForReading in OpenTextFile method. You need to use the values "1" instead of the constant. So replace "ForReading" with "1". Here is the updated script:

SUB mReadDelimitedFile()

  Set objFSO = CreateObject("Scripting.FileSystemObject")

  msgbox 2

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

  msgbox 3

END SUB

Thanks,

DV


www.QlikShare.com

j_nlucas
Partner - Contributor III
Partner - Contributor III
Author

Excellent!

Thank you