2 Replies Latest reply: Nov 17, 2016 9:40 PM by Tamil Nagaraj RSS

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

    geekwho geekwho

      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!

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

          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
            Tamil Nagaraj

            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