Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
jiwaniakbiar
Contributor II
Contributor II

How to save a excel file with filename as current selection

Hi

I need help to save excel with Current Selection as file name. Also if there is nothing selected, it should save as default name

I tried to setup a variable which will hold current selection value and use it in the macro but it doesn't work.

Varialbe declared in Document Properties as:

vSelection = (replace(GetCurrentSelections(),': ','_')

and Macro is:

set v = ActiveDocument.Variables("vSelection")

Selection = v.GetContent.String

Path = "C:\qlikview\"

FileName = Selection & "_Report" & ".xlsx"

ActiveDocument.Sheets("REC Dashboard").Activate

MsgBox(FileName)

objExcelWorkbook.SaveAs Path & FileName

MsgBox("File Saved Successfully in C:\qlikview\"+Selection+".xls")

It works for a single fiield is selected. If I have more than one Field selected, it doesn't work because vSelection sends string in two lines

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Try:

vSelection = replace(replace(GetCurrentSelections(),': ','_'),chr(13)chr(10),'_')


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Try:

vSelection = replace(replace(GetCurrentSelections(),': ','_'),chr(13)chr(10),'_')


talk is cheap, supply exceeds demand
jiwaniakbiar
Contributor II
Contributor II
Author

It worked. Thnx. However can you please help me what exactly you did with chr(13) and chr(10)?

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Getcurrentselections inserts a linebreak between the results of different fields. The linebreak consists of two ascii characters, a Carriage Return (chr 13) and a Line Feed (chr 10). I replaced them with an underscore '_'.


talk is cheap, supply exceeds demand
jiwaniakbiar
Contributor II
Contributor II
Author

Also I used following to default 'No Selection' to filename 'Overall'

= IF((Nullcount (SubStringCount( GetCurrentSelections(':'),':'))),'Overall',replace(replace(GetCurrentSelections(),': ','_'),chr(13)&chr(10),'_'))