SSIS - Copy Excel sheet and delete from old - excel

I need some advice around copying Excel files and then keeping a 'template' once it's moved. I have a bunch of Excel files that need to be loaded into SQL. The names might differ, i.e. Excel_Test1, Excel_Test2. These files are processed into SQL. Once this is done I have to copy them into an Archive folder. The problem is if I move instead of copy I get the error in my SSIS package where it says object doesn't exist. What can I do to ensure it doesn't happen? Is there a way to copy the files to archive, and then create a dynamic Excel sheet for next time? Or is there an easier way of doing this? Steps are:
Truncate Staging Table.
Load first table.
Load second table.
Move / copy files to archive.
I hope I'm making sense.

Keep one version of file in Template folder
(it can contain fake data if it make sense), then copy actual file to archive after processing, and then override the actual file with file from Template folder.

Related

How to exctract specific data and file name form multiple excel files pladec in one folder?

I am looking for a solution to shorten the time of going through the excel files during tender preparation.
I was thinking of creatin a master excel file that would be placed above the folder which would contain all excel files i want to extract. I would like to extract the name of the file and place it in the specific column, and summarized data from one row in that file, to be placed in ther counterpart in the master folder. Main project folder can be located on any hard drives location. The master file and parts files would have the same layout inside.
The Structure would look like :
Project folder "some name">>
Master tender file,
Folder for parts calculation>>
Excel calculation for part 1,
Excel calculation for part n,
Is it possible to do something like that? i am learnig vba but the thing i did up until now is code for clearing the master file.

Data Copy using Excel-VBA

I am having a folder of 10 excel-based CSV files. Is there any method to copy the data from all these files into 1 excel
Not good with VBA, so thought to ask you guys
On a first sight, I would go for the following approach (coming up with the codes is up to you, Google is your friend):
Get a list of all file names within that directory
Iterate over every item from the above list and open the file with Workbooks.Open(...)
Copy the whole content and paste it to the additional Excel you want to manage to hold the data of all files
Repeat the steps for each file
Remember to save the last row after every paste s.t. you can continue with amending the data into the addtional Excel instead of replacing the content.

How to combine multiple Excel files?

I have multiple Excel files in the same format and I want to combine them into a single file.
How can I merge them into one single excel file using VBA?
VBA is no longer required to merge files. You can use Power Query and merge all files in the same folder with just a few clicks. When the files change, you just update the query.
You have two choices:
a "flat" file, in which all the data are in a single sheet (BAD)
A multi-sheet file (GOOD)
In the first case open a new file, cut and paste your existing content into the new (single) sheet
In the second case Move/Copy the sheets to a New Document.
There: you now have enough Google fodder to get you started.
I had this same issue a while back and found an excellent solution thanks to my good friend Google. All credit for this solution goes to the following page: computer hope
To merge Microsoft Excel files together, save them as CSV files first (it would be possible to automate this part in VBA if there is a recurrent need). Open the Excel files and in the menu bar, click File, then Save As. In the Save as type drop-down list, select CSV (comma delimited) (*.csv) from the list.
Do this for each Excel file you want to merge, then place all the CSV files in the same folder. For ease, place them in a folder in the root of the C: drive (e.g., c:\csvfiles).
Open the Windows command prompt (to get to this, in the Search or Run line, type cmd and press return) and navigate to the folder containing the CSV files. Type dir to view the files in the folder and ensure all the files are there.
Type in the following command to merge all CSV files in the folder into a new CSV file titled "newfile.csv" (any name could be used):
copy *.csv newfile.csv
After the new file is created, open the new CSV file in Microsoft Excel and save it as an Excel file.

Batch save pictures from multiple excel files in a folder

I have about 10000 excel files, that in a specific cell of all of them there is a picture. I need a script to read all files and save the picture with the same name of the excel files in a folder.
Could you please help with that?
Thanks.
This method is based on a number of assumptions:
All the files (10000) are located in a know folder,
All files are named according to a paradigm that can be reproduced programmatically (if not, you can get the list of files within the folder, store the list within an array, and loop through the array),
Pictures are always within the same worksheet or, if in more than one, the names of the worksheets can be reproduced programmatically,
The filenames to be used to save the pictures can match (at least as a seed) the one of the Excel the pictures are extracted,
You will manage to write some basic VBA.
Note that for the VBA you have at least two options:
Write it within an EXCEL that will only serve as the extraction engine, or
Write it as a stand-alone file and run it via DOS commands.
The VBA logic:
Create the outer loop that processes a single file,
Within the outer loop, generate the name of a file to be open,
Open the file using Workbooks.Open VBA function,
Select the worksheet and the cell containing the picture,
Use the Workbook.SaveAs to save the picture (you will need to specify the type of file to be used, e.g. .bmp).
As a simple and very efficient tool to get the code (at least) partially generated by Excel, you can RECORD a MACRO for each action and then stop recording. You will see the code generated (you will need to access the VBA mode). You can copy-paste the generated code into your development (you might need to do some simple adaptations though).
That's it.
Hope you manage. Good luck!!

Opening 2 files with the same Name but different directories

I have written a macro which opens 2 comma delimited files (Generic Tables used by Prophet 8.1 ending with a .fac extension), does a comparison and creates another workbook which highlights all the differences.
The macro seems to fail when the files have the same name but has different directories.
What would be the easiest way to overcome this problem without having to actually change the file name as seen in the location? It is against company policy to mess with the actual files as seen in the location. Is there a way to assign some temporary name to the file and not save it?
In Excel you cannot have two files open with the same name!
If you don't want to rename the files, copy one temporarily using a different name - and delete it afterwards (assuming you only want to read from it)
If you have to modify/save the original files, then the only two options you have is to rename them (you can afterwards rename them back to the original name) - or change your procedure so only one file is open at the time (e.g. by temporarily storing some data from the first file in a temp workbook that gets created and closed during the code execution).

Resources