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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

loop over possible fields

I have a table

CMR      MAIL

1       1@TEST.COM

2       22@TEST.COM

2       236@TEST.COM

I have a field named CMR in qlikview

How could I loop over possible CMR and send the mail group by mail ?

I use the following script

SUB xlsExport

DIM varDate

DIM d

DIM xlApp

DIM xlBook

DIM xlSheet

DIM strSheetName

DIM FieldName

DIM ff

DIM v

DIM varAutomation

SET v = ActiveDocument.Variables("vTriggerMacro")

  varAutomation = v.GetContent.STRING

IF varAutomation <> 1 THEN

  confirmation = MSGBOX ("Excel export has been initiated." & vbCrLf & "Do you wish to continue?"& vbCrLf &"",  36, "Export Confirmation")

  IF confirmation = 7 THEN

  EXIT SUB

  END IF

END IF

SET d = ActiveDocument.Variables("vDate")

  varDate = d.GetContent.STRING

XLSFile = "c:\export-email-automation\ExcelReport_"&varDate&".xls"

SET ff = ActiveDocument.Variables("vFieldName")

  FieldName = ff.GetContent.STRING

SET xlApp = CREATEOBJECT("Excel.Application")

  xlApp.Visible = FALSE

SET xlBook = xlApp.Workbooks.Add

SET xlSheet = xlBook.Worksheets("Feuil1")

SET Doc = ActiveDocument

SET Field = Doc.Fields(FieldName).GetPossibleValues

FOR i=0 to Field.Count-1

  Doc.Fields(FieldName).Clear

  Doc.FIelds(FieldName).SELECT Field.Item(i).Text

  Doc.GetApplication.WaitForIdle

  Doc.GetSheetObject("CH461").CopyTableToClipBoard TRUE

  xlApp.ActiveSheet.Paste

  xlApp.Worksheets(xlApp.ActiveSheet.Index).Cells.EntireColumn.AutoFit

  xlApp.Worksheets(xlApp.ActiveSheet.Index).Cells.EntireRow.AutoFit

  strSheetName = Field.Item(i).Text

  xlApp.ActiveSheet.Name = strSheetName

  IF(i<Field.Count-1)THEN

  IF(i>=2)THEN

  xlApp.ActiveWorkbook.Worksheets.Add

  END IF

  IF(i<2) THEN

  xlApp.Worksheets(xlApp.ActiveSheet.Index +1).SELECT

  END IF

  END IF

NEXT

Doc.Fields(FieldName).Clear

xlApp.DisplayAlerts = FALSE

xlBook.SaveAs XLSFile, 56

xlBook.Close

IF varAutomation <> 1 THEN

MSGBOX "Excel export is complete!",64,"[Insert Company Name] Business Intelligence"

END IF

END SUB

MSGBOX "Excel export is complete!",64,"[Insert Company Name] Business Intelligence"

END IF

END SUB

1 Reply
mightyqlikers
Creator III
Creator III

hi

for i=0 to Mail.count-1

your code

next

ActiveDocument.Fields("Mail").Clear

Regards

$@M