Downloads

Adding Intellisense to a DNA solution.

A few people have asked how to add intellisense to a DNA solution. Obviously for someone like me who knows the object model so well and has perfect spelling etc.* its not needed, but for lesser mortals here’s how its done!

Setup up a DNA project in the normal way, then download the PIA of your choice.

Wooo, hang on what the hells a PIA?!?!.

A PIA, or Primary Interop Assembly, is a dot Net assembly that lets you use  COM object “stuff” in/from managed code. They are generally considered a pain in the posterior, hey maybe that’s really what PIA stands for…Pain In Ar…! Anyway, see here for a bit more detail.

I’ve saved you some time, by collecting all the available ones here. But you might already have them on your PC, if you do they will be in C:\WINDOWS\assembly\, called something like  “Microsoft.Office.Interop.Excel.XX.dll” where XX is the office version number…

Oh, more pain… now the thing is there’s a PIA for each version of Office/Excel. Each PIA supports the OM for a specific version, so using the 2007 one and deploying the solution against a 2003 version of Excel might cause a problem. DNA does not need the PIA as it uses the C API to talk to Excel, but to get intellisense we need to use a PIA. Oh, and theres no PIA for Excel 2000, but you can roll you own (add a reference to the Excel.exe, and the IDE will make a “IA” , the “Primary” is dropped as its not from the vendor, it gets messy here, lets move on – quickly!)

OK, so, setup up a DNA project in the normal way, download the above .Zip file and extract to your hard disk. Go to the “Project” menu, “Add reference”, then “.Net assembly Browser” then go and find the PIA folder you just extracted, and pick the right version for your needs. Here I’m targeting Office XP!

Notice that a reference is added to the project for the PIA, and can be seen in the project viewer.


Now, how to get it to work. Well the exact way is up to you, but if your using a module to hold a global reference to the Excel application, like we suggested before, then in that module change to code to something like this:


Imports Microsoft.Office.Interop.Excel
  Public Module Globals
      Public zXL As Application
  End Module

Then back in you class module you can use intellisense, ace.

Before you build the final version, make sure you remove the reference to the PIA, you can just delete it from the project viewer, and then delete the dll from the debug/release directory (i.e….\\Intellisense Example\bin\Debug\)

And there you go!

One other thing to note is that it works a little bit better in Visual Studio, SharpDevelop also exposes events, which you can’t use in every content, obviously, but its no big deal!

* vbg – on both counts!

Introduction to Microsoft Excel Array Functions

This post is by guest blogger Yoav Eze, his bio can be fond at the bottom of the post. Thanks Yoav!
It’s always nice to get content from other Excel developers, so if you have an interesting story, please feel free to share it here!!! Get in touch: rossmcleanatgoogledotcom
That now makes a list of 2 guest bloggers on MIE in 5 years, Sam and Yoav, I’m hoping to grow that list!!!
Now, over to Yoav
.
.
Array functions are a super-useful feature of Microsoft Excel and other competing spreadsheet packages. These functions help you deal with lists, and if you consider how many lists you encounter in your daily life and work, you will see how important making it easy to work with them can be!
To demonstrate how to work with arrays, we downloaded a PDF containing a study of Walmart, and produced a comparison of prices between U.S. and Mexican branches of the stores in Excel. You can take a look at the sample file by downloading Average.xlsx.
As you will see, some of the prices are lower in the U.S., and some are lower in Mexico. How can we see the average ratio of prices that are higher in the U.S., and the average ratio of prices that are lower? We can either break the table into two, one with the lower prices, and the other with higher, or we can use an array function – the conditional average function.
.
Conditional Averages and AverageIf
Up to Excel 2007, the only way to get the result we want was to use array formulas. In Excel 2007, a new formula was introduced to perform just this kind of operation, called AVERAGEIF. We have provided samples of both ways (as array formulas are still supported in Excel 2007).
The AVERAGEIF function takes two parameters (it can take three, but we’ll keep it simple here): the range to work on – just like the regular AVERAGE function – and a condition, represented as a string. The formula evaluates the condition for each cell in the range; if it’s TRUE, then the contents of the cell are counted in the average; if it’s FALSE, they’re ignored. In our sample, the condition is “>100%” for prices that are more expensive in the U.S., and “<100%” for products less expensive.
The older array formulas are a little trickier. To use them, you basically write the regular formula – in this case, AVERAGE; but instead of the range, you put in an IF formula on the range.
The IF formula contains a condition and a value, and they are specified as ranges. This is not valid syntax normally, but it is valid in an array formula. To let Excel know that this is an array formula, you need to press Shift+Ctrl+Enter when you finish typing in the formula instead of the regular Enter. Excel will display curly brackets around the formula in the Formula Bar – note that this is not actually part of the formula, so you cannot just edit those in – you have to do this particular three-key combination enter.
In our sample, we use ‘range>100%’ as the IF condition, and the range (which will be translated as the value of the cell) as the return value if the condition is true. If the condition is false, the IF doesn’t return anything, so the outside AVERAGE formula does not take it into account. To demonstrate this, we can use the ‘Evaluate Formula’ command on the array formula cell:
The formula evaluation starts with the original formula:
We can use the Evaluate button to proceed to the next stage; in this case, expand the range into the values in the cells it contains:
And then, it displays the result of evaluating the condition for each cell:
Now it replaces each TRUE value with the contents of the cells to use in the outside formula; the rest are left as FALSE.
Note that AVERAGE disregards the FALSE values, and so the average comes out correctly.
And finally the result:
Summary
If you ever wanted to calculate, sum, or count items in a list based on certain conditions then you need to get to grips with array formulas. Hopefully this short, hypothetical example has given you a taste for what these useful functions can do and you can now set about working with your own lists.
.
About the author
Yoav Ezer co-authors the technology and productivity blog Codswallop. He is also the CEO of a company that produces PDF to XLS conversion software.
For more Excel tips from Yoav, join him on Facebook or Twitter

An Excel eBay Sold Prices Search Tool

I wanted to buy a Blackberry for work, my company don’t provide me with one, preferring smoke signals instead ;-). Obviously I didn’t want to pay top dollar for it so it was off to eBay in search of a bargain. I noticed there was a large spread of prices for the same phone, which lead me to wonder if I could research the sold prices for various items.

It turns out that you can’t via eBay, but some other company does provide an API (with a free option) which can be used to search the sold prices.   Long story short here is a file that you can use to get the prices. You’ll need to get a developers key first though, at:

https://developer.ebay.com/join/Default.aspx

Mine took a day to come through….

“User Guide…”

Get your AppID key and paste it in the “eBay developers App ID” box, then type something in the keyword box, then pick a currency then and parent category, then a child one. Click search!. If you can’t find anything in this category, try a slightly different set of keywords, of check the “search all” box, to search the all the listings.

The “update category data” link under the child category drop down updates the data in the category dropdowns as eBay change them form time to time.

Note on quality….

Over all I’m a bit disappointed by the whole thing. As I’ve thought about it, while writing the app, it’s dawned on me that it’s quite a tricky thing to do. You see the problem is, eBay gets hammered by people selling links to things, or multiply items, or broken things, or replicas, or mis-listings (something listed as “Oakley sunglass, but when you read the detail it says there not actually Oakley’s but they look like them etc), so getting a true average price is actually quite hard… I’m not sure I trust the results. As the API does not return a list of all the items that go into the average price you can’t eye ball the data. But it’s better than nothing I guess.

Download the workbook here:

Unit testing Excel VBA – xlUnit demo

Back in February I did a podcast with Mike Woodhouse, based around testing VBA code. Mike has written a unit testing frame work for VBA code, called xlUnit. Over the last few weeks I’ve been using xlUnit to help write a generic validation class for VBA, so I thought I would put together a little video of how the addin can be used to write tests for your code.

Its in 2 parts because you can only upload videos that are 10 minutes long to you tube.  The first part is the basics and in the second part I show some examples from my project.

You can find out more about xlUnit at Mikes blog, grumpy old programer:

Playing Video Files in VBA forms

A bit more from the past, in this example file you can play a video natively within a VBA form – cool!

videoform

The example file here: Video API