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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
janardhan
Creator
Creator

Macro

Hi Friends ,

I need code for macro's....

In the below table 3 rows of data is there , i need to create one or separate csv file for each ACCNUM or row

ACCNUM
NAME
Hours
111yyy90
222zzz100
333xxx150

Thanks,

Jana

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Try the code below (adapted from this) and create two variable vfname to hold your field name and vMacroChartId to hold the ID of the chart you use for the export. Attached is also an example file so you can see how it works.

SUB AdHocExport

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

        IF confirmation = 7 THEN

            EXIT SUB

        END IF

DIM FileName

DIM var

DIM fname

SET f = ActiveDocument.Variables("vfname")

    fname = f.GetContent.STRING

SET v = ActiveDocument.Variables("vMacroChartId")

    var = v.GetContent.STRING

    ActiveDocument.Fields(fname).Clear

SET Doc = ActiveDocument

SET Field = Doc.Fields(fname).GetPossibleValues

FOR i=0 to Field.Count-1

    Doc.Fields(fname).Clear

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

    Doc.GetApplication.WaitForIdle

    FileName = Field.Item(i).Text & ".csv"

          Doc.GetSheetObject(var).Export FileName, ","

NEXT

Doc.Fields(fname).Clear

MSGBOX "Ad hoc CSV export is complete!",64,"Task Completion Notification"

END SUB


talk is cheap, supply exceeds demand

View solution in original post

7 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Try the code below (adapted from this) and create two variable vfname to hold your field name and vMacroChartId to hold the ID of the chart you use for the export. Attached is also an example file so you can see how it works.

SUB AdHocExport

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

        IF confirmation = 7 THEN

            EXIT SUB

        END IF

DIM FileName

DIM var

DIM fname

SET f = ActiveDocument.Variables("vfname")

    fname = f.GetContent.STRING

SET v = ActiveDocument.Variables("vMacroChartId")

    var = v.GetContent.STRING

    ActiveDocument.Fields(fname).Clear

SET Doc = ActiveDocument

SET Field = Doc.Fields(fname).GetPossibleValues

FOR i=0 to Field.Count-1

    Doc.Fields(fname).Clear

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

    Doc.GetApplication.WaitForIdle

    FileName = Field.Item(i).Text & ".csv"

          Doc.GetSheetObject(var).Export FileName, ","

NEXT

Doc.Fields(fname).Clear

MSGBOX "Ad hoc CSV export is complete!",64,"Task Completion Notification"

END SUB


talk is cheap, supply exceeds demand
Not applicable

hi janardhan

Sub table

          'Get the table we want to export

          Set t1 = ActiveDocument.GetSheetObject("CH01")

          t1.Export "tables.txt", ","

          Set obj = CreateObject("Scripting.FileSystemObject")

          Set objTextFile = obj.OpenTextFile ("tables.txt", 8, True)

          objTextFile.WriteLine("")
          objTextFile.Close

         

          Set t2 = ActiveDocument.GetSheetObject("CH02")

          t2.Export "tables.txt", ",", , TRUE

End Sub

and use this link.

http://community.qlik.com/thread/40999

janardhan
Creator
Creator
Author

Thanks a lot Wassenaar... Its working exactly

Thanks for your help...

sorry about late response

janardhan
Creator
Creator
Author

Hi Wassenar ,

i am attaching my application can u pls modify the Macro

i have tried but it is not working.

Advance Thanks for  help

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Here you go. I changed the value of the variable fname to Accountnum. And I changed this line back to how it was:

SET Field = Doc.Fields(fname).GetPossibleValues

You can change the path where the files are save by changing the line FileName = Field.Item(i).Text & ".csv"  to FileName = "C:\somewhere\" &Field.Item(i).Text & ".csv"


talk is cheap, supply exceeds demand
janardhan
Creator
Creator
Author

Hi Wassenaar ,

Yeah its working , its aweosome

Can u pls tell me where u have modified in the code.

And may i know in which path it is saving the csv files.

And I need to set some particular path .

Thanks for ur help and spending time for me

janardhan
Creator
Creator
Author

Hi Wassenaar ,

its working, thanks a lot

Advance Happy New Year 2013