Automate insert/run macro for ETL process - excel

I'm trying to automate an ETL process in which a flat file (.xlsx) is placed into a folder and then a macro I built performs all the necessary transformations to the file. Right now I have to open the original .xlsx file then manually insert/run the macro (the macro saves and closes the file automatically). From here I have a program that automatically loads the transformed file into my db.
I was wondering what I could do to automate the inserting and running the macro step?

You need to save your workbook as an xlsm or xlsb file, as xlsx workbooks can't contain any vba code. After that, you can run your macro, either manually, or from a worksheet button.

Related

How to copy an active excel sheet and save it into a new workbook using a vbs script?

I'm trying to copy an excel sheet that includes formulas and paste it into a new excel workbook as values and retaining the format using vbs script.
I'm currently doing it but instead of copying I'm saving it as a CSV.
So it is only saving the first page but it looses the format.
Please help.
Thank you.
I found a way around to fix this, I run a vbs to refresh and save the file. then with a batch file i run another script and open the file to only run a macro inside of it and the macro does the job.

Excel - Best file format for macro and forms

I make a lot of workbooks where there is no data in the workbooks themselves, but there are macros and forms attached. I generally format these in .xlsb or occasionally .xlsm file format, but I'm wondering if there is a format where there is no actual workbook attached. Just like a file you can open in Excel that will launch the macro?
It just seems pretty inefficient to include a blank workbook that I just autohide on load.
Depending on the version of Excel, when you load up Excel it automatically opens a Personal workbook which isn't visible.
Normally this is created when you record a macro and close all windows. It will then ask you to save it to the file. I would then set up shortcuts for the Macros.

Once Excel sheets in a workbook saved as .csv, cant get back to .xlsm

I have a workbook with multiple sheets. I press a (ribbon) button and a subroutine saves multiple sheets as .csv, shells out to some java code, then comes back. The problem is: once it comes back, the workbook has been converted to a .csv file (the last one saved) and no further .xlsm operations are possible.
How do I fix this?
Amendment:
Has nothing to do with Java or shell. WHENEVER I do this:
Sheets("someSheet").SaveAs Filename:=someName, FileFormat:=xlCSV
this changes the ENTIRE workbook to someSheet.csv. Then, the behavior of the workbook gets weird. I haven't been able to save as .csv without changing EVERYthing.
Use SaveCopyAs.
It leaves your original workbook as is and saves a copy. Requires 2007 or newer but since you mention a ribbon button that should be fine. From the link:
ActiveWorkbook.SaveCopyAs "C:\TEMP\XXXX.XLS"
http://msdn.microsoft.com/en-us/library/office/bb178003(v=office.12).aspx
In Excel, the Save As operation, creates a new copy of the workbook with the new name and format/style, then closes the old one.
A .csv file doesn't support macros, so your workbook is behaving as designed.
In order to get back to your original workbook after doing the Save As, you will need to re-open the original workbook and then close the new .csv workbook.
Otherwise, you could come up with a custom Export method to just export the data on each sheet to a .csv file, but that seems needlessly complex.

Update a csv file used by Quality Center with a macro

I have a csv files containing iterations that will be imported into HP Quality Center and used to perform automated testing.
Some of the data in these files must be updated every month and I have created a macro for each to do this.
I cannot keep the macro and the csv on the one workbook as QC does not allow anything other than csv files to be imported (not that I know of).
I realise I can import the macro each time but there are many csv files and many macros.
Is there some format or work-around that would allow me to keep the macro on the csv file, so when I open it I can just hit Alt+F8 and run the macro?
Save your macros in your personal workbook (personal.xslb), rather than in the individual data files. Then they will be available to run your updates on the csv files without being stored in the files.

Batch file opening Excel file and Macro

I want to create a batch file which when I run this file, an excel file should open with some columns in it.
Say if I click on batch file, excel file with columns name, project, ID should also get included in excel file.
Also with this a macro should be open.
Please help. I dont have any idea about this.
I don't think it is possible to automate excel with pure batch.
Why not:
Create an "template" excel file with the default columns and macro included
Have a batch file copy this template (copy template.xslx newfile.xslx) file and open it (`Start newfile.xslx).
For the new file, you'd either have to generate a random or timestamp-based name or have the user enter the name before making a copy.

Resources