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: 
Not applicable

Output table to external file with file called today's date

Hi All,

I am trying to get a maco working that will export a table to a file that is named according to date i.e.

The file should be created with the name fdnyymmddhhmm.csv Where

yy = last two digits of the current year
mm = the current month
dd = current date with leading zero as appropriate
hh = current hour in 24 hour format "23" for 11 p.m.
mm = current minutes with leading zero i.e. "05"


Example filename = fdn0904091410.csv when the file was created at 14:10 on the 9 April

Has anybody had any luck with this before. I have tried for a couple of hours and can't seem to get it right.

Thanks in advance

Bob



1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Bob,

I think that the easier way is to use QV functionality. You can create variable based on now() function, formated the way you want, something like:
='fdn' & timestamp(now(), 'YYMMDDhhmm') & '.csv'
And use it in your macro as the file name

I forgot about the Evaluate - with it you don't even need macro. Try this:


sub test
File = activedocument.Evaluate("'fdb' & timestamp(now(), 'YYMMDDhhmm') & '.csv'")
msgbox(File)
end sub

I assume you can do the rest of coding

View solution in original post

4 Replies
Anonymous
Not applicable
Author

Bob,

I think that the easier way is to use QV functionality. You can create variable based on now() function, formated the way you want, something like:
='fdn' & timestamp(now(), 'YYMMDDhhmm') & '.csv'
And use it in your macro as the file name

I forgot about the Evaluate - with it you don't even need macro. Try this:


sub test
File = activedocument.Evaluate("'fdb' & timestamp(now(), 'YYMMDDhhmm') & '.csv'")
msgbox(File)
end sub

I assume you can do the rest of coding

Not applicable
Author

Thanks Michael for your replies,

I thought I could do the rest of the coding...

sub test
set a=ActiveDocument.GetSheetObject("TB01")
File = ActiveDocument.Evaluate("'fdb' & timestamp(now(), 'YYMMDDhhmm') & '.csv'")
a.Export (File)
msgbox(File)
end sub

But this does not work, nor does a.SaveAs.

Any more help greatly appreciated

Bob

Anonymous
Not applicable
Author

Bob,
This macro works fine for me:


sub test
set obj = ActiveDocument.GetSheetObject("TB01")
File = activedocument.Evaluate("'fdb' & timestamp(now(), 'YYMMDDhhmm') & '.csv'")
obj.Export File, ";"
end sub

It creates the file in the same directory with qvw. But you can add the path to the file name in the macro - hardcoded or as a variable.

Not applicable
Author

Thank you so much - this worked perfectly 🙂

Bob