Jump to content

Multiple Excel Files Generation from Master Excel File


Recommended Posts

Try something like:

#include <Excel.au3>

Local $sSourcePath = "C:\Users\JPSITI\Desktop\Autoit"
    If FileExists($sSourcePath) = 0 Then DirCreate($sSourcePath)
Local $sTargetPath = "C:\Users\JPSITI\Desktop\Autoit"
    If FileExists($sTargetPath) = 0 Then DirCreate($sTargetPath)

Local $sSourceBook = @ScriptDir & "\Test Scope.xlsx" ;$sSourcePath & "\Test Scope.xlsx"

Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox(4096, "Excel Error", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $oSourceBook = _Excel_BookOpen($oExcel, $sSourceBook)
    If @error Then
        MsgBox(4096, "Excel Error", "Error opening workbook '" & $sSourceBook & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

Local $oSourceRange, $oTargetBook, $sTargetBook, $x = 1

For $i = 4 To 10
    $oSourceRange = _Excel_RangeRead($oSourceBook,"Test Scope","D" & $i)
    $sTargetBook = $sTargetPath & "\" & $x & ".xlsx"
    $oTargetBook = _Excel_BookOpen($oExcel, $sTargetBook)
        If @error Then $oTargetBook = _Excel_BookNew($oExcel)
    _Excel_RangeWrite($oTargetBook, Default, $oSourceRange, "C" & $i)
    _Excel_BookSaveAs($oTargetBook, $sTargetBook, $xlWorkbookDefault)
    _Excel_BookClose($oTargetBook)
    $x += 1
Next

 

Edited by Subz
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...