Mass export to excel - data selection based on keys

32 posts / 0 new
Last post
Baricha Saddam Ali
Offline
Joined: 04/13/2017 - 03:47

Dear Brian
Thank you very much for your response. I appreciate your help. I have a challenge understanding the code you wrote. I am new to IDEA.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Baricha,

Well the script I would consider for advanced users as it has you creating code to manipulate Excel.  I will try and explain what the script does.  In the Sub Main you are setting up your list of IDEA files that you want exported and then merged into one Excel file.  You then call the createExcelSheet function.

It first creates an array sExcelName() to hold the names of the Excel file names.  The array is made the same size as the sExcelExportList by using the ubound function (this gets the number of items in an array or the upper boundary of an array).

For For Next loop takes the name of the IDEA filed, strips off the IMD and adds the XLSX file extension.  It then calls the IDEA task to export the file to the Exports.ILB directory under the project folder.

At this point you have all your files as separate Excel files.

The next block of code creates an Excel object and creates a new Excel file in the Exports.ILB folder that will hold all your separate Excel files.

The next block then uses a for next loop that opens each individual Excel spreadsheet, copies the information from the worksheet and then pastes it into a new worksheet in your new Excel spreadsheet.  The code then does an autofit so that the column widths show all the information.

It then closes each of the Excel spreadsheets, once everything has been copied over it saves the new worksheet, closes it and exists Excel.

Hopefully that makes a bit more sense.

Thanks

Brian

Baricha Saddam Ali
Offline
Joined: 04/13/2017 - 03:47

Dear Brian
I replaced the values in the script and got error 39 (Invalid Database).
Set db = Client.OpenDatabase(sExcelExportList(i)) 
Please see attached.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Change the:

ReDim sExcelExportList(5)

to

ReDim sExcelExportList(3)

If you don't it will be looking for 6 databases instead of your 4.

Baricha Saddam Ali
Offline
Joined: 04/13/2017 - 03:47

Dear Brian
Thank very much, the explanation makes sense.
 

Baricha Saddam Ali
Offline
Joined: 04/13/2017 - 03:47

Dear Brain
It has partly worked, It exported the 4 files to my IDEA exports but failed creating a new excel workbook for combining the 4 files. 
Kindly note i had done this
Set fso = CreateObject("Scripting.FileSystemObject")
workDir = Client.WorkingDirectory
Path = workDir
 
Kindly see attached.

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Barachi,

Thanks for also posting the code.  From your code this is mostly like the problem. You placed:

Const EXCEL_FILENAME = "Bulk_Results.XLSX" 'name of new excel file

In the sub main, you need this as a global variable so remove it from the sub main and place it above the sub main, in the area where you declare your Global variables.

That should hopefully fix your error.

Brian

Baricha Saddam Ali
Offline
Joined: 04/13/2017 - 03:47

Dear Brian 
Apologies for the late response. I want to thank you immensely for your assistance. The code has worked perfectly!. Thank you very much.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

My pleasure, glad you have it working.

Brian

Baricha Saddam Ali
Offline
Joined: 04/13/2017 - 03:47

Dear Brian
One last question. How do I add "check file exist" on exportation script. I tried as attached and it did not work

Pages