Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Export chart to csv with current data and time in name of file

Hello everybody!

I'm trying to export a .csv with current data and time in name of file using VB macros.

My idea is to concatenate location of file with current data using now() function but i get an error

SUB ExportChartToCSV

Dim vendas As String = "C:\Users\usuario\Desktop\ftp\vendasLOCCBC"+now()+".csv"

Dim qtd As String = "C:\Users\usuario\Desktop\ftp\qtdLOCCBC"+now()+".csv"

Dim ticket As String = "C:\Users\usuario\Desktop\ftp\ticketLOCCBC"+now()+".csv"

SET  objChart = ActiveDocument.GetSheetObject("CH01")

     objChart.Export vendas, ","

     SET  objChart = ActiveDocument.GetSheetObject("CH03")

     objChart.Export qtd, ","

     SET  objChart = ActiveDocument.GetSheetObject("CH04")

     objChart.Export ticket, ","

END SUB

This code below is working but everytime i export, the new file overwrite the old file.

SUB ExportChartToCSV

     SET  objChart = ActiveDocument.GetSheetObject("CH01")

     objChart.Export "C:\Users\usuario\Desktop\src\ftp\vendasLoccBM.csv", ","

     SET  objChart = ActiveDocument.GetSheetObject("CH03")

     objChart.Export "C:\Users\usuario\Desktop\src\ftp\qtdLoccBM.csv", ","

     SET  objChart = ActiveDocument.GetSheetObject("CH04")

     objChart.Export "C:\Users\usuario\Desktop\src\ftp\ticketsLoccBM.csv", ","

END SUB

Somebody could help me? Please

I really dont know VBA and i know this suppose to be easy!

Tags (5)
2 Replies
Employee
Employee

Re: Export chart to csv with current data and time in name of file

Use

n = ActiveDocument.Evaluate("=Date(Today(),'DDMMYYYY')") ' Or other format

Dim vendas As String = "C:\Users\usuario\Desktop\ftp\vendasLOCCBC"&n&".csv"

Re: Export chart to csv with current data and time in name of file

Hi,

You can use Qlikview functions inside the macro by using the syntax ActiveDocument.Evaluate("=Function name"). In your case you can use below code,ActiveDocument.Evaluate("=

ActiveDocument.Evaluate("

Sub ExportChartToCSV

vDate = ActiveDocument.Evaluate("=Date(Now(),'DD-MM-YYYY HHMMSS')") ' Current Date and time

SET  objChart = ActiveDocument.GetSheetObject("CH01")

objChart.Export "C:\Users\usuario\Desktop\src\ftp\vendasLoccBM_" & vDate & ".csv" , ","

SET  objChart = ActiveDocument.GetSheetObject("CH03")

objChart.Export "C:\Users\usuario\Desktop\src\ftp\qtdLoccBM_" & vDate & ".csv" , ","

SET  objChart = ActiveDocument.GetSheetObject("CH04")

objChart.Export "C:\Users\usuario\Desktop\src\ftp\ticketsLoccBM_" & vDate & ".csv" , ","

End Sub