I created an SSIS package that extracts data from SQL and load it into excel. I am having problem making this package dynamic and loading data into multiple excel files. 

I first created an execute SQL task that holds all the file names with SQL code: `SELECT FileName FROM Files` and its result set will be stored in a variable `FileNameObj`. Then I created a Foreach Loop Container and added a Data Flow Task inside. 

**Foreach Loop Container setting:** Foreach ADO Enumerator, ADO Object source variable - `FileNameObj`, Variable mapping - `FileName` and Index - 0. Under data flow task, I have added an OLE DB Source and Excel Destination pointed to file path: `C:\Test\ABC.xlsx` . 

**Here is the Connection Manager Property:**

**ConnectionString**: `Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Test\ABC.xlsx;Extended Properties="Excel 12.0;HDR=YES";`

**DelayValidation** set to `True`

**ExcelFilePath** is `C:\Test\ABC.xlsx`

Then I created an expression with Property `ExcelFilePath` and Expression: `"C:\\Test\\"+ @[User::FileName]+".xlsx"`
Then my **ConnectionString** changes to: `Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Test\.xlsx;Extended Properties="Excel 12.0;HDR=YES";`

I have created all my files templates (same structure for all) in test folder already. I get the following error:

> 
> Error at Data Flow Task [Excel Destination [131]]: SSIS Error Code DTS\_E\_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E37.
> 
> 
> Error at Data Flow Task [Excel Destination [131]]: Opening a rowset for "Sheet1$" failed. Check that the object exists in the database.
> 
> 
> Exception from HRESULT: 0xC02020E8 (Microsoft.SqlServer.DTSPipelineWrap)
> 
> 
> 

What am I doing wrong? Or is it even possible to do this in SSIS?

![1](https://i.stack.imgur.com/sxMns.jpg)

![2](https://i.stack.imgur.com/NBTgy.jpg)

![3]](https://i.stack.imgur.com/64v0l.jpg)

![4]](https://i.stack.imgur.com/DYshD.jpg)

![5]](https://i.stack.imgur.com/l0cBT.jpg)

![6]](https://i.stack.imgur.com/7WNVT.jpg)

![7]](https://i.stack.imgur.com/GDeva.jpg)

![8]](https://i.stack.imgur.com/jATKU.jpg)

![9]](https://i.stack.imgur.com/6izwF.jpg)

![10](https://i.stack.imgur.com/U3Kot.jpg)

![11](https://i.stack.imgur.com/oZuOb.jpg)

![12](https://i.stack.imgur.com/2UjIo.jpg)