Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 |
---|---|---|
111 | yyy | 90 |
222 | zzz | 100 |
333 | xxx | 150 |
Thanks,
Jana
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
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
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.
Thanks a lot Wassenaar... Its working exactly
Thanks for your help...
sorry about late response
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
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"
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
Hi Wassenaar ,
its working, thanks a lot
Advance Happy New Year 2013