Jump to content

Merge several Excel workbooks into another multiple-sheet workbook


Deon
 Share

Recommended Posts

Hi,

I have a script which fetches 7 excel files from our company's webserver and saves them as a file.

I then create a new spreadsheet with 7 tabs and copy-paste each of the 7 files into it's own tab.

I'm trying to automate this and not having much luck. I've tried using _Excel_RangeCopyPaste and failed abysmally, and then in desperation tried using Send() to send ctrl and tab keys but I really want a cleaner way.

I would paste the code I have, but I overwrote the one using the Excel UDF, and you really don't want to see the one with a hundred Send()'s and Sleep()'s in it.

I'd really appreciate any help anyone can offer! I've been using AutoIt for a while, so even if you can push me in the right direction, I can continue from there :)

 

Cheers,
Deon.

Edited by Deon
Link to comment
Share on other sites

Something like this?

#include <Excel.au3>
#include <File.au3>
Global $aWorkbooks[] = ["C:\temp\WB1.xlsx", "C:\temp\WB2.xlsx"]
Global $sDrive, $sDir, $sFileName, $sExtension
$oExcel = _Excel_Open()
$oWorkbookOut = _Excel_BookNew($oExcel, 1)
For $i = 0 To UBound($aWorkbooks, 1) - 1
    $oWorkbookIn = _Excel_BookOpen($oExcel, $aWorkbooks[$i], True)
    $oSheet = _Excel_SheetCopyMove($oWorkbookIn, 1, $oWorkbookOut, $i + 1)
    _Pathsplit($aWorkbooks[$i], $sDrive, $sDir, $sFileName, $sExtension)
    $oSheet.Name = $sFileName
    _Excel_BookClose($oWorkbookIn)
Next

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Glad to be of service :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...