Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Customer & Partners, DEC. 9, 11 AM ET: Qlik Product & Strategy Roadmap Session: Data Analytics REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
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!

2 Replies
Clever_Anjos
Employee
Employee

Use

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

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

tamilarasu
Champion
Champion

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