Excel Macros on Informatica - vba

I am trying to load an Excel which has macros, now challenge is to run the macros before loading that data, and we are using Informatica for data loading.
Do we have any way to run the Macros on Excel using informatica and then load the data?

I am little bit confused about your question ( not clear about the scenario you are describing). What I can suggest is:
Step 1: It will be great if you can convert the macro into a vbscript (.vbs file). Alternatively, if you find that tough, write a small vb script that will call the macro. Follow the link Marek Grzenkowicz provided in comment.
Step 2: Add one command task in your informatica mapping. Then add this vbscript file name with full path in "commands" field so that when the command task will run, it will call the vbscript file.

Related

Use VBA in some form to edit or create more VBA code for a file that will be distributed

So whilst I tried to make the title as clear as possible I will expand on it here.
I am trying to create a new macro, the data for that macro will come from Pastebin, this file would be distributed to many people in different countries. Thus my goal would be to be able to modify or update macros in one shape or form, I can do an easy test to check if there are updates but could not figure out how to modify a macro, I would happily create a new excel workbook temporarily that has these macros or possibly create a VBScript and that creates a macro, not sure of the best method to do this.
What I have done so far, form tons of searching how to programmatically moidfy macros is form the website cpearson
However this needs the modification of security which has to be done one each computer that will use this file and that is just not a possibility.
If you need more clarification on the question feel free to drop a comment, (might reply tomorrow)
Any suggestions on how to modify or import macros or workarounds to achieve the desired effect would be amazing.
This sounds like something I made a couple of years ago. (It's company property now so I can't redistribute it). Here is the general idea with PasteBin as source:
You can do this by creating a VBA-injector and placing the module name in the top of the Pastebin.
changesMadeDate|
Modulename1 updateDate1|
//your code here
|Modulename2 updateDate2|
//and so on
If you are working with just Modules, UserForms and Classes this is pretty doable but stay away from Worksheetcode because then you can't use the remove and add method but would instead have to rewrite the sheet code with SendKeys. (Unreliable)
What you need to do (using modules as example):
Create a Pastebin that contains all the modules as described above.
Create a methods to split the Pastebin data and save each module locally as moduleName + ".bas" using FSO.
Remove and add modules to the current project.
You can use this to also create a updateDate for each module and only update those that are newer. Just add a updateDate after Modulename in the Pastebin.
You can distribute just the VBA injector and everyone can use the modules after running the update. Also add changesMadeDate before the first module name in Pastebin and you can create a Workbook_open event that checks it to know if to run the update at all.
If you exceed the Pastebin char limit then just do:
ModuleName1 pastebinlink1|
ModuleName2 pastebinlink2|
Then go from there. Using a shared textfile would probably work better though.
Edit: You could also delete all but injector modules. Then add empty modules and use VBIDE.VBComponent.CodeModule then write into them, but I prefer the first way.

How to script Excel 2013's Spreadsheet Compare?

I'm trying to incorporate the fancy new Spreadsheet Compare function from Excel 2013's Inquire Add-in, into a VBA script.
The plan is to have a macro to automate comparison between two spreadsheets with predefined names, and to export all the differences as a new spreadsheet.
Without success, to date.
Here's what I've tried so far:
Normally, to learn how to automate some Excel functionality, I use Record Macro.
If that fails, I look down the list of addable references, to see if I'm missing something obvious.
Both of those have failed in this case. No code appeared relevant to the Spreadsheet Compare, when I recorded a macro (only the peripheral stuff like cell-select appeared). And none of the addable references looked anything like Spreadsheet Compare.
So how can I script Excel's 2013 Spreadsheet Compare, from VBA?
I opened a similar question for automating the Spreadsheet Compare tool from a .NET application, but I haven't found any other way yet than executing it from command-line.
You can do this from your VBA add-in. All you need is to locate the executable file SPREADSHEETCOMPARE.EXE (usually in C:\Program Files (x86)\Microsoft Office\Office15\DCF) and to execute it in command-line with an instruction file as input argument.
This instruction file must be an ASCII file with the two Excel file paths to compare written in separate lines.
You can't.
VBA does not cover add'ins as in this case.
Spreadsheet compare is a 3rd party plugin which got swallowed by Microsoft.
If you need scriptable compare you can find those which do for each cell, for each row... kind of thing on the net.
Create a runCompare.cmd file:
REM Execute from command line spreadsheetcompare.exe
REM
cd C:\Program Files (x86)\Microsoft Office 2013\Office15\DCF
spreadsheetcompare.exe C:\reportNames.txt
In C:\reportNames.txt, save in the same line the .xlsx files you wish to compare:
C:\fileA.xlsx C:\fileB.xlsx
Execute runCompare.cmd.

Automated Excel document creation using VBA

The managing director at our company wants me to produce an automated monthly document that saves to a certain place on our system so that he doesn't have to manually input all of the data. I have set up so that the document can save to the correct place in the correct format but my knowledge of VBA is not great.
Tackling this from a 1 question at a time point of view I suppose my question would be is it possible to create 1 very long macro that will accomplish many different tasks over several workbooks. For example we have a report that comes from our ERP (Baan) and shoves all of the data into one cell. Is it possible to create a macro that will accomplish formatting text to columns, then copy data from a cell based on a row reference and then take said data and paste it in to a different workbook? Would it then be able to save the workbook all from just running one macro and if so how long will all of that take once the macro is executed?
Yes I believe this should be do-able, keeping in mind that the file names + location remain the same (otherwise you'll have to edit each month). Create different Subs/Functions and call them in one main macro.
The easiest way is probably to do it step by step. Record macro's and see whether that already helps you out and if not use google & stackoverflow for help! :)
it is entirely possible - but in my Opinion VBA is not well suited to the task. The editor is atrocius at best and it is easy to produce highly specific "spaghetti code".
File operatione are possible, but are not nice. Error handling is 80s style with lots of goto.
So if you want to build something maintainable, build an external Application using Interop or epplus (.net package for reading /writing to excel documents) or an .net addin for office.

Manipulate Excel workbooks programmatically

I have an Excel workbook that I want to use as a template. It has several worksheets setup, one that produces the pretty graphs and summarizes the numbers. Sheet 1 needs to be populated with data that is generated by another program. The data comes in a tab delimited file.
Currently the user imports the tab delimited file into a new Workbook, selects all and copies. Then goes to the template and pastes the data into sheet1.
This is a large amount of data, 269 columns and over 135,000 rows. It’s a cumbersome process and the users are not experienced Excel users. All they really want is the pretty graphs.
I would like to add a step after the program that generates the data to programmatically automate the process the user currently must do manually.
Can anyone suggest the best method/programming language that could accomplish this?
POI is the answer. Look at the Apache website. You can use java to read the data and place it in cells. The examples are very easy.
You can can solve this, for example, by a simple VBA macro. Just use the macro recorder to record the steps the user does manually now, this will give you something to start with (you probably will have to add a function to let the user choose the import file).
You said you have some data generated by another program. What kind of program? A program that you have developed by yourself and where you can add the excel-import functionality? Or a third party program with a GUI that cannot be automated easily?
And if you really want to create an external program for this task - choose whatever programming lanuguage you like as long as it can use COM objects. In .NET, you have the option of using VSTO, but I would only suggest that for this task if you have already some experience with that (but than you would not ask this kind of question, I think :-))
Look here:
Create Excel (.XLS and .XLSX) file from C#
There's NPOI (.NET Framework version of POI) so that you can code in C# if you want.
If you use two workbooks - one for data and one for graphs - and don't update links automatically you can use a macro to get the data (maybe an ODBC connection if the file is in a format it can read - long shot) and then link the charts to the data workbook.
Use a macro to update the links and generate the charts and then send them out and hope no one updates the links.

Excel save as on Run

In Excel, after writing a VBA script, I would like Excel to save the file before running it.
It is common on most of the programming tools.
While testing a program, it may crash and my program may not be saved but if it saves before each run, I won't have this problem anymore.
I know there is a automatically save option in Excel but is there another alternative ?
Add
ActiveWorkbook.Save
at the beginning of your macro