Freigeben über


UDFs in Visual Studio 2005 Tools for Office: put your VBA where it belongs

I fielded a question from an eager VSTO developer in the forums. It was about the UDF-managed code support we added in VSTO- a screaming feature. Basically, you can create User-defined functions in manage code and then make them available from your VBA code. Paul Stubbs has a blog entry about how to get going with this: https://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx

The basics are there, but you need to keep in mind a couple of things in order to make this work:

1) You have to make sure you have enabled macros in Excel. UDFs are called from VBA, so if the macro security prohibits VBA from running, your managed code UDF will never get called even if the .NET security is properly configured.

2) You need to make sure that the VBA code for hooking up the managed code world to the unmanaged world is in the code module for the target sheet. I moved it to different locations (custom bas module, workbook module) and it does not work.

If you do these things, it should work out for you. It's great stuff.

Rock Thought for the Day: I keep re-visiting my feelings about nu-metal. I'd like to say that I really don't like the whole genre, dismissing it as stuccato guitar thump with over-dramatized lyrics. Most of it is. But, there are enough songs from different bands to cobble together a likeable collection. Sevendust complicate things for me. There is a song here, a song there where I say, "Great stuff. What else has this band done? I'd love to here more" ("Pieces" off their new album, "Next" is a decent example). But, I'm ultimately disappointed, and I feel like tossing the whole nu-"metal" bands in the scrap heap. Metal has become too conformist. This is where Metallica still leads the way. Sure, St. Anger was a risky album in a lot of ways. The band tried new things. But, that's the beauty of it all. Whereas I used to hold up "And Justice for All..." as the best album they produced (yes, I'm a dissenter from the "Black" album mainstream), I find myself completely won over by St. Anger, although it took some time. I hear things in there that are truly amazing, innovative, dare I say- Original. Sevendust, Staind, Trapt, yaddah yaddah- not original, nothing ground-breaking, no big risks, no immortality in the rock universe. Sorry guys. I like some of your songs, and you are truly sensational in your craft. It's well done music and a decent amount of soul. But I still nagged by the memory of something I haven't yet heard. I'm waiting for a band to let me hear it.

Rock On