Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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
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
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
Thank you so much - this worked perfectly 🙂
Bob