Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Export and rename object in excel file

Hello Everybody,

That is my first post on the forum. I read a lot of other post about this topic but i did not find the expected information.

I'm building a pricing tool and i would like to export my price recommandation dashboard in a specific folder (always the same) and with a specific name i want to specify each time i save one file.....

I try to modify one existing VBA macro but i can't modify the name of the file. Can you help me?

sub ExcelFile

  set obj = ActiveDocument.GetSheetObject("CH19")

   

obj.Export "C:\Documents\Files\QvProjects\Custo\\data\custo_in_"&Date&".xls",","

end sub

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Try this...

Create a variable in your qvw called vDate and make the expression for it be =date(today(),'DD-MM-YY')

SUB ExcelFile

DIM varDate,d

'get today's date from qvw variable

     SET d = ActiveDocument.Variables("vDate")

          varDate = d.GetContent.STRING

'get object to export from qvw

     set obj = ActiveDocument.GetSheetObject("CH19")

   

'export object to file location in excel format

'     obj.ExportEx "C:\Documents\Files\QvProjects\Custo\\data\custo_in_"&varDate&".xls" , 6

obj.ExportBiff "C:\Documents\Files\QvProjects\Custo\\data\custo_in_"&varDate&".xls"

END SUB

Message was edited by: autopilot - added ExportBiff in place of ExportEx

Message was edited by: autopilot - modified date variable to replace "/" symbol format

View solution in original post

3 Replies
er_mohit
Master II
Master II

Try this

Sub Exceltest

     'Set the path where the excel will be saved

     filePath = "E:\Test.xls"

     'Create the Excel spreadsheet

     Set excelFile = CreateObject("Excel.Application")

     excelFile.Visible = true

     'Create the WorkBook

     Set curWorkBook = excelFile.WorkBooks.Add

     'Create the Sheet

     Set curSheet = curWorkBook.WorkSheets(1)

     'Get the chart we want to export

     Set tableToExport = ActiveDocument.GetSheetObject("CH19")

     Set chartProperties = tableToExport.GetProperties

     tableToExport.CopyTableToClipboard true

     'Get the caption

     chartCaption = tableToExport.GetCaption.Name.v

     'MsgBox chartCaption

     'Set the first cell with the caption

     curSheet.Range("A1") = chartCaption

     'Paste the rest of the chart

     curSheet.Paste curSheet.Range("A2")

     excelFile.Visible = true

XLApp.DisplayAlerts = False

     'Save the file and quit excel

     curWorkBook.SaveAs filePath

     curWorkBook.Close

     excelFile.Quit

     'Cleanup

     Set curWorkBook = nothing

     Set excelFile = nothing

     set  XLApp = nothing

End Sub

Hope it helps

Anonymous
Not applicable
Author

Try this...

Create a variable in your qvw called vDate and make the expression for it be =date(today(),'DD-MM-YY')

SUB ExcelFile

DIM varDate,d

'get today's date from qvw variable

     SET d = ActiveDocument.Variables("vDate")

          varDate = d.GetContent.STRING

'get object to export from qvw

     set obj = ActiveDocument.GetSheetObject("CH19")

   

'export object to file location in excel format

'     obj.ExportEx "C:\Documents\Files\QvProjects\Custo\\data\custo_in_"&varDate&".xls" , 6

obj.ExportBiff "C:\Documents\Files\QvProjects\Custo\\data\custo_in_"&varDate&".xls"

END SUB

Message was edited by: autopilot - added ExportBiff in place of ExportEx

Message was edited by: autopilot - modified date variable to replace "/" symbol format

Not applicable
Author

Many thanks Autopilot....it's the good one