4 Replies Latest reply: Nov 17, 2012 2:01 AM by Gysbert Wassenaar RSS

    How to save a excel file with filename as current selection

    Akbar Jiwani

      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