Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

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

Create / export .txt file from button

Hi Everybody,

how can i create an empty .txt file from my dashboard with a button?

I need to create on my desktop an empty .txt file with this naming convention :

XX_YY_GG-MM-AAAA_HH-MM-SS.txt


where GG-MM-AAAA_HH-MM-SS represent the now().


Thanks Everybody!

M



3 Replies

Re: Create / export .txt file from button

Hi,

May be this macro will help...

Create one field without value and use it as a ListBox, (Here the object ID LB01) .

Create one Button, Assign the below Macro

sub Test()

      set obj = ActiveDocument.GetSheetObject("LB01")

          path=ActiveDocument.Evaluate("=Replace(DocumentPath(),subfield(DocumentPath(),'\',-1),'')")

          fname=ActiveDocument.Evaluate("=Timestamp(now(),'DD-MM-YYYYY_hh-mm-ss')")

      obj.Export path&"\XX_YY_"&fname&".txt",","

end sub

Or, You can create two variables, and use it in your macro.. Like

sub Test_1()

      set obj = ActiveDocument.GetSheetObject("LB01")

      set path=ActiveDocument.GetVariable("vPath")

      set fname=ActiveDocument.GetVariable("vFile")

      filename=path.getcontent.string&"XX_YY"&fname.getcontent.string&".txt"

      obj.Export filename,","

end sub

Check the Attachment..

MVP
MVP

Re: Create / export .txt file from button

You don't need to export a dummy object, rather use the vbscript fso api:

fname = "\XX_YY_" & ActiveDocument.Evaluate("=Timestamp(now(),'DD-MM-YYYYY_hh-mm-ss')") & ".txt"

Set filesys = CreateObject("Scripting.FileSystemObject")

Set filetxt = filesys.CreateTextFile(fname, True)

filetxt.Close

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable

Re: Create / export   .txt file from button

Thanks Jonathan,

finally i've used this macro:

sub EXPORT()

dim a
a = now()

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Users\marcello.aondio\Desktop\Sorgenia 2\" & "TASK_NOMETASKAA_UTENTEQV_" & left(a,2) & "-" & Right(Left(a, 5), 2) & "-" & Right(Left(a, 10), 4) & "_" &Right(Left(a, 13), 2)& "-" &Right(Left(a, 16), 2)& "-" &Right(Left(a, 19), 2)& ".txt")

end sub

Community Browser