views:

18

answers:

0

I've got an Excel 2007 Workbook that uses mixed VSTO/VBA automation that I'm trying to deploy. Everything was working pretty well, but now I'm running into a stubborn issue with allowing my VBA code to make calls into the VSTO compiled code.

I've set up my VBA and code-behind according to the walkthrough posted at http://msdn.microsoft.com/en-us/library/bb608613.aspx. However, when VBA tries to declare an instance of my C# class, I get the following error:

Dim VSTOSheet1 As CallingCodeFromVBA.Sheet1
  ^ Compile Error: Can't find project or library

(Note that I'm using the same variable names as the linked walkthrough for the purposes of this question)

If I play around with the VBA editor, the limited VBA intellisense shows me that VBA knows about a reference called CallingCodeFromVBA, but not about the methods within it.

Here's where things get weird: in the VBA editor, I now add a new sub:

sub test()
    dim o as CallingCodeFromVBA.Sheet1
end sub

Then I delete the sub I just added. So, my VBA ends up being unmodified from the original.

And now everything works. WTF!

Obviously the act of writing the new sub caused VBA to do some binding on its references, and allowed the other code to work. My question is, why? And how can I get my code to work without having users break in to VBA, write a random sub, then delete it?

To clarify, this is a Workbook add-in, not an Excel application add-in.