Skip to main content

Mass export to excel - data selection based on keys

Hi there,
I am dealing with a mass export of data from idea databases to e.g. excel files now, but unfortunatelly I am not getting on well with that. :-(
I will try to describe the situation:
I prepared a database containing accounting data (booking entries) in IDEA. Then I did a selection based on key values (Data - Selections - Selection based on key values...). The key value is an G/L Account. IDEA created several individual databases (imd files) - for each key value (G/L Account) one database. Now I want to export all the individual databases to excel. There is no option to do that on mass. In case of big amount of key values (e.g. 100), it is annoying to do the export 1 by 1.
I tried to do a test script: I did the export for one value (G/L account 1) first, then I copied the script from "History" and extend the script for the second value (G/L account 2). When I triggerred the script, it went to error ("Error on line xx - Duplicate definition: myArray).
Is there any chance to do the mass export from IDEA?
Thank you for any idea. :-)
Dan

Brian Element Tue, 03/07/2017 - 17:02

In reply to by mobbie

Hi Mobbie,

I just tried it in an 9.2 environment and didn't have any problems.  I guess the next step is if you could post a screen grab of the error.  Another thing you can try is exporting the IDEA database by itself to see if IDEA gives an error when you do that.

Thanks

Brian

mobbie Wed, 03/08/2017 - 05:08

In reply to by Brian Element

I don't have any trouble when  exporting IDEA database by itself.
I've upload the IMD files and the script for export to excel. Please help me to review it.
I can select the folder, then selecting the files (Template-Restruk-RES.IMD and Template-Sektor-SEK.IMD). When I click Ok, then error show up with line 174 (image attached).

Brian Element Wed, 03/08/2017 - 07:27

In reply to by mobbie

Hi Mobbie,

Did you try the script that I attached?  http://ideascripting.com/sites/default/files/forum_files/Export%20Multiple%20Databases_0.iss as that one seems to be working.  The scripts attached here are not mine, they were developed by someone at CaseWare IDEA.  At this stage I would have to redevelop the script to get it working properly but the one I attached did run without the error you were getting (and I also got it when I tried to run it). 

There is also a SmartAnalyzer application that helps doing this that you might want to look at, you can find it here: https://ca.marketplace.audicon.net/ca_en/excel-export-utility.html

Unfortuatately right now I don't have the time to redo this script to make it work properly.

Thanks

Brian

 

Baricha Saddam Ali Wed, 08/30/2017 - 02:29

Hello guys,
Kindly assist. I am trying to export different IDEA databases into one excel file
'EXPORTATION OF BULK AND PAYBILL SCRIPTS
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_BULK_FAILED_TRXNS
Set db = Client.OpenDatabase("BULK_FAILED_TRXNS_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\BULK\BULK_FAILED_TRXNS_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_BULK_RECONCILED
Set db = Client.OpenDatabase("BULK_RECONCILED_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\BULK\BULK_RECONCILED_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_BULK_SUSPICIOUS_TRXNS
Set db = Client.OpenDatabase("BULK_SUSPICIOUS_TRXNS_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\BULK\BULK_SUSPICIOUS_TRXNS_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_BULK_CHARGES
Set db = Client.OpenDatabase("BULK_CHARGES_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\BULK\BULK_CHARGES_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_PAYBILL_FAILED_TRXNS
Set db = Client.OpenDatabase("PAYBILL_FAILED_TRXNS_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\PAYBILL\PAYBILL_FAILED_TRXNS_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_PAYBILL_RECONCILED
Set db = Client.OpenDatabase("PAYBILL_RECONCILED_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\PAYBILL\PAYBILL_RECONCILED_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_PAYBILL_SUSPICIOUS_TRXNS
Set db = Client.OpenDatabase("PAYBILL_SUSPICIOUS_TRXNS_" & Reconciliation_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\PAYBILL\PAYBILL_SUSPICIOUS_TRXNS_" & Reconciliation_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 
' File - Export Database: XLSX
Function ExportDatabaseXLSX_REVERSALS
Set db = Client.OpenDatabase("REVERSALS_" & Previous_Date & ".IMD")
Set task = db.ExportDatabase
task.IncludeAllFields
eqn = ""
task.PerformTask "Z:\00-IDEA FILES\MPESA\PAYBILL\REVERSALS_" & Previous_Date & ".XLSX", "Database", "XLSX", 1, db.Count, eqn
Set db = Nothing
Set task = Nothing
End Function
 

Baricha Saddam Ali Wed, 08/30/2017 - 02:44

Apologies, I forgot to mention that I want to save the databases on different sheets but on one workbook save with the reconciliation date

Brian Element Wed, 08/30/2017 - 19:39

In reply to by Baricha Saddam Ali

Hi Baricha,

Sorry today was very busy, I will try and find some time tomorrow to take a look at this.

Brian

Brian Element Thu, 08/31/2017 - 16:59

Hi Baricha,

Here is something that hopefully you can use or adapt to your script.  This example (I have also attached the script) will work on the files in the sample project folder.  The constant at the beginning of the script holds the name of the excel file you want to save your databases into.  The array holds the name of the databases you want to copy over.  The code in the createExcelSheet copies each excel spreadsheet into a new sheet of the new excel sheet.

Let me know if you have any questions or problems.

Brian


'Option Explicit
 
Const EXCEL_FILENAME = "Results.XLSX" 'name of new excel file
 
Dim sExcelExportList() As String
 
Sub Main
	ReDim sExcelExportList(5) 'array to hold the databases to combine
	sExcelExportList(0) = "Sample-Customers.IMD"
	sExcelExportList(1) = "Sample-Employees.IMD"
	sExcelExportList(2) = "Sample-Inventory.IMD"
	sExcelExportList(3) = "Sample-Payments.IMD"
	sExcelExportList(4) = "Sample-Suppliers.IMD"
	sExcelExportList(5) = "Sample-Weblog.IMD"
	
	Call createExcelSheet()
	MsgBox "Script Complete"
End Sub
 
Function createExcelSheet()
	Dim db As database
	Dim task As task
	Dim eqn As String
	Dim i As Integer
	Dim sExcelName() As String 'array to hold the excel name
	Dim ApExcel As Object 'variable to hold the excel object
	Dim oWorkbook1 As Object 'variable to hold the first workbook
	Dim oWorkbook2 As Object 'variable to hold the second workbook
	Dim oWorksheet As Object
	Dim oRange As Object
	Dim sSheetName As String
	'1st export databases
	
	ReDim sExcelName(UBound(sExcelExportList)) 'redim the excel name array to the same size as the number of files
	
	'export all the IDEA databases to an excel file
	For i = 0 To UBound(sExcelExportList)
		Set db = Client.OpenDatabase(sExcelExportList(i))
			Set task = db.ExportDatabase
				task.IncludeAllFields
				eqn = ""
				sExcelName(i) = Mid(sExcelExportList(i), 1, Len( sExcelExportList(i)) - 3) & "XLSX"
				
				task.PerformTask Client.WorkingDirectory & "Exports.ILB\" & sExcelName(i) , "Database", "XLSX", 1, db.Count, eqn   
			Set task = Nothing
			db.close
		Set db = Nothing
	Next i
               
	'create spreadsheet to combine the files to
	Set ApExcel = CreateObject("Excel.application")                              
		'xlsversion= ApExcel.Version
		ApExcel.Workbooks.Add
		ApExcel.activeWorkbook.Saveas(FileName:=Client.WorkingDirectory & "Exports.ILB\" & EXCEL_FILENAME )
		ApExcel.quit
	Set ApExcel=Nothing       


	Set ApExcel = CreateObject("Excel.application") 
		'create an object to hold the excel workbook that will hold the IDEA databases
		Set oWorkbook1=ApExcel.Workbooks.Open(Client.WorkingDirectory & "Exports.ILB\" & EXCEL_FILENAME )
			For i = 0 To UBound(sExcelExportList)
				'remove XLSX from the excel name in order to name the sheet
				sSheetName = Mid(sExcelName(i) , 1, Len(sExcelName(i)) - 5)  
				'Open each of the IDEA files that have been saved as an excel file           
				Set oWorkBook2=ApExcel.Workbooks.Open(Client.WorkingDirectory & "Exports.ILB\" & sExcelName(i) )
					'copy the information from the excel file
					oWorkBook2.activesheet.UsedRange.Copy
					'add a new worksheet to the excel file that the information will be copied to
					oWorkbook1.WorkSheets.Add
					'rename the sheet to the name of the IDEA database
					oWorkbook1.ActiveSheet.Name = sSheetName
					'paste the information into the sheet
					oWorkbook1.ActiveSheet.Paste
					'get the worksheet so that the columns can be autofitted.
					Set oWorksheet=oWorkbook1.Worksheets(sSheetName)
						Set oRange=oWorksheet.UsedRange
							oRange.EntireColumn.Autofit
						Set oRange = Nothing
					Set oWorkSheet = Nothing
					'save the workbook, this avoids getting the windows dialog about a large amount of information, do you want to keep it.                             
					oWorkBook2.Save
					'close the workbook
					oWorkBook2.Close
				Set oWorkBook2 = Nothing
			Next i
			'save the new excel spreadsheet
			oWorkbook1.Save
			oWorkbook1.Close
		Set oWorkbook1 = Nothing
		'quit excel
		ApExcel.Quit
	Set ApExcel=Nothing
End Function