How to script Excel 2013's Spreadsheet Compare? - vba

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.

Related

VBS or VBA for Multiple Excel Files?

Here is what I need to do:
I have around 1000 folders, within each of these folders is an excel file that I need to reformat (all the excel files are similarly formatted), I imagine the actual programming part is quite easy but that is besides the point. If I need to run a script on each of these excel files, should I use VBA or VBS?
As far as I understand, VBS can be run from the command line and doesn't require any Excel files to be open but VBA does require Excel to be open in order to run the script but that seems counter intuitive since I need to run a script on not just one workbook but a thousand.
Any help will be appreciated.
Many thanks.
Edit: I should say explicitly, I am trying to convert around 1000 CSV files to XLSX, I have tried python packages such as OpenPYXL and XLSXwriter but they are just terribly slow - it takes around 5 minutes per file.
I suggest you to use Python with the openpyxl package to implement your idea. The openpyxl package is intuitively easy to use, while Python's flexibility will allow you to get the job done in short term.

Excel Macros on Informatica

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.

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.

Automation: how to automate transforming .doc to .docx?

I have a bunch of .doc files in a folder which I need to convert to .docx.
To manually convert the .doc to .docx is pretty simple:
Open .doc in Word 2007
Click on Save As...
Save it as .docx
However, doing this for hundreds of files definitely ain't fun. =p
How would you automate this?
There is no need to automate Word, which is rather slow and brittle due to pop-up messages, or to use Microsoft's Office File Converter (ofc.exe), which has an unnecessarily complicated user interface.
The simplest and fastest way would be to install either Office 2007 or download and install the Compatibility Pack from Microsoft (if not already done). Then you can convert from .doc to .docx easily using the following command:
"C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme <input file> <output file>
where <input file> and <output file> need to be fully qualified path names.
The command can be easily applied to multiple documents using for:
for %F in (*.doc) do "C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme "%F" "%Fx"
The easiest way is to use the command-line Office File Converter. Just run
ofc
and the magic happens.
Automate Word.
If you are using .NET, add Microsoft.Office.Interop.Word (make sure it is version 12 - equivalent to Word 2007 so you can achieve the above) reference assembly to your project and use it it automate word app to do exactly what you want to do above. The pseudocode
Create the application object
Use the application object to open a document (by supplying it the file name)
Use the application object to perform SaveAs by supplying to it the format and output filename
Close the current document
Loop through the above till you finish with all documents
Housekeeping code to release the Word or Doc objects
You can find plenty of example on google, just search for Word Automation in C# or something along that line.

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