COM

64 bit VBA

In my last post, VBA Version 7  Daniel, author of Daniel’s XL Toolbox, commented that he had not come across anything untoward with the “new!” version of VBA, and reported, so far, all is well with his addin – good news! Then JP from Code For Excel & Outlook, pointed to a  VBA Compatibility tool (tool, info) from MS – thanks JP, I think this is called team work! ;-)

Anyway, I believe the major update might be support of 64 bit types in VBA?  I’m not running a 64 bit OS to test, but I found this:

Excel 2010 can load much larger workbooks. Excel 2010 made updates to use 64-bit memory addressing in order to move beyond the 2-GB addressable memory boundary that limits 32-bit applications.

The down side of this is:

Visual Basic for Applications (VBA)   VBA code that uses the Declare statement to access the Windows application programming interface (API) or other DLL entry points will see differences between 32-bit and 64-bit versions. The Declare statement must be updated with the PtrSafe attribute after inputs and outputs to the API have been reviewed and updated. Declare statements will not work in 64-bit VBA without the PtrSafe attribute. New data types are added to 64-bit Office 2010 VBA: LongLong and LongPtr. For more information about VBA, see the “64-bit VBA Overview” and “Declare Statement” articles in the Microsoft Visual Basic for Applications online Help in Office applications.

So if your using API calls in you VBA, and you hit a 64 bit versions, you could be about to hit some issue. Doesn’t sound like the fix will be to hard though, but we’ll wait and see eh!

Bonus thought: Does this mean the C API has been updated too?

.Net 4.0 imporvments, Good for Office Devlopers!

I’ve bogged before about version 4.0 of .Net and what it could mean for Office devs. Here’s one other improvement I didn’t know about:

Improvements to Interop Marshaling in V4: IL Stubs Everywhere

The article sums it up thus:

· Faster interop marshaling: the more complex the signature the greater the speed-up

· x86 and x64 behavior matches: we’ve updated the x64 marshaling to behave exactly as x86 always has and mostly without impact to x64

· Better debugging: when something goes wrong in marshaling we now give you the ability, and specialized tools, to find the problem

There’s actual another important effect of the IL Stubs, and that is that the PIA is version independent. In fact the CRL will create it dynamical at run time. So now you can target all version of Office from one 4.0 addin – cool.

I’ll wait a see what the performance increase in like from 3.5 – that sounds like a post in its self!

A Devlopers Tool of Choice?

When we talk about which language to use we often, if not always get talking about the technical advantages of a given tool, XLL’s are faster than VBA, VBA is easier to deploy than VSTO, VSTO is more secure than VBA, and so on and so on. Simon has some information here and I have some .Net stuff here. But one aspect that’s over looked is what each offers the developer.

Let’s consider an example. I’m writing a adding for the users in my department, it needs to contain some UDF’s, apply a custom formatting option to a selected range, help import a strangely formatted XML file, and link to a database and pull back some data. What are you going to write that in?

Well from a technical point of view you might like to used an XLL for the UDF’s, a Com adding for the formatting and database stuff and make use of some .Net classes for the XML processing. Nice!

For 90 percent of us, we will solve every problem using VBA, simply because that’s the only tool we have. But what if?

Here’s what I think different technologies offer the developer, not the technological advantage, it the things that make the developer’s live more enjoyable!

VBA: For simple stuff it’s quickest. As things get more complex and or the difficulty of what you are trying to do gets harder VBA becomes more of an effort (think of userform stuff, VBA, vs .Net?!). If you need something that needs constant changes, or something that you expect to grow in size over a period of time it might be worth doing it VBA.

VB6 (Com addins): If the UI you need is a bit more complex, than it might be time to switch to VB6, the more powerful forms and use of active X components means that you can have more choice when designing them. Also from a deployment POV, you have to worry less about the thing being installed on the PC, as you can compile them into the DLL

As the size and complexity of the project increases, switching to VB6 can be a help. Functionality can be complied in to different parts, external libraries can be used and packaged easily, source code can be shared with other developers – although this is rare for Excel projects.

Another good reason for a developer to pick VB6 com adding over VBA ones is that, although generally VB6 code can be changed with little effort to run in VBA, there are times when VBA does not quite have the same feature set, and dropping some code straight in to a VB6 com addin is just easier than messing around trying to convert it to VBA.

VSTO: Well its IDE isn’t 100 years old, thats a big plus! But the most compelling reason why an Excel dev would want to use VSTO, would be to make use of the framework. Forms are incredibly powerful in .Net (form namespace), but so too is all the functionality that the framework provided, like the threading name space, or the services name space. When we start to try and do really grand stuff, .Net is brilliant.

C/C++ [XLL]: Purely from an easy of development POV, I can only really think of 2 things XLL would over. One would be a situation where you need to deploy is a “hostile” environment, so the extra work in the coding would be repaid in the effort saved deploying. The other would be if there is a C library with some complex functions in it, a bit like with the VB/VBA issue, it might just be easier to keep the C code and wrap it up in a XLL.

VSTA: What’s VSTA?!?!

So there you go that’s my take on it, disagree?

Working with Colours in Excel – M.I.E Colour Manager

Here is the BETA version of my Colour Manager, and tool for creating colour pallets in Excel:

ColouPalletManager.PNG

It’s a VB6 com addin, the only thing you really need to know is that you load a picture on the left and then click that picture to get the colour at that point. You can then click a pallet square to place it where that square is. Click the send to workbook button to send it to the active workbook.

However I have also made a video to show how to use it. Bosh!

Here is the file!

UPDATED FILE HERE:
MIE Colour Manager Beta 0.3.0.zip

Enjoy, feedback more than welcome.

Is Managed Code Slower Than Unmanaged Code?

What’s you gut answer right now; without reading the rest of this post?

In my (seemingly) never-ending quest along the path of Uncapacitated Facility Location problems, I found myself thinking if I would be better of write some core functions in C (unmanaged) and calling them in my VB.net project? I thought that it probably would be, but decided to check first. Here’s the link, you can skip to the conclusion at the end for the low-down:
http://www.grimes.demon.co.uk/dotnet/man_unman.htm