1

Just like the title says, i'm unable to have access to anything pass the "VBProject" object from an active document in c#. When i try to get the list of componenents (modules) from the VBProject object this way :

var components = Globals.addInName.Application.ActiveDocument.VBProject.VBComponents;

I get the following error at compile time in c# :

 error CS1061: 'object' does not contain a definition for 'VBComponents'

However, what's funny is that if i remove "VBComponents" and use the debugger to explore the variable, i can see a VBComponents, as well as the number of modules available in the document. I really don't understand how visual studio is unable to find it. I tried including Microsoft.Vbe.Interop; without much success. While i'm now able to have a VBComponents type, i am still unable to compile.

I have the following usings in my project at the moment :

using Visio = Microsoft.Office.Interop.Visio;
using Office = Microsoft.Office.Core;
using VBE = Microsoft.Vbe.Interop;

I've honestly searched for many hours, included various references in my project, but without any success. I simply cannot compile my addin. Yet i'm able to do it very easily in vba with almost the same syntax.

Is there anything i am missing?

zaedas98
  • 13
  • 1
  • 3
  • 1
    The VBProject property can only be used late-bound. Assign it to a variable of type *dynamic*. – Hans Passant Dec 22 '16 at 19:05
  • Well, seems like you are correct. It does work with the dynamic type. I had never heard of that type before. What's the difference between dynamic and var then? I don't see any difference between them. The MSDN isn't very clear on that either. Would you mind posting your comment as an answer so i can accept it? – zaedas98 Dec 22 '16 at 20:10
  • http://stackoverflow.com/questions/961581/whats-the-difference-between-dynamicc-4-and-var – Jbjstam Dec 29 '16 at 14:29

0 Answers0