Macro access to NodeXL

Jun 27, 2014 at 2:36 PM
Currently I'm using Excel VBA to collect and visualize data from a SQL database. My Code creates custom graphics and afterwards accesses MS Word to load a report template and copies the graphs into the report.

I need a network graph in my report and found NodeXL which creates exactly what I need. Is there a way to use NodeXL output in my report? I'm familiar with Excel VBA as well as .net, so any help is appreciated.
Jun 27, 2014 at 4:37 PM
Please clarify what you mean by using NodeXL output in your report. Do you mean that you have an edge list and you would like to generate a graph image from that edge list? If so, there is a "NodeXL Class Libraries" release that will let you do that from any .NET application. It's under the "Other Downloads" section on the NodeXL Downloads tab at I'm not sure if that's what you're asking for, though...

-- Tony
Jun 28, 2014 at 7:29 AM
Hello Tony!
Thank you for the response.
Yes, I would like to use a NodeXL generated graph in my report. I already read about using the Class Libraries but as the application code is an Excel VBA Macro, I can't use them as easily as I like since I have to create COM wrappers. As this is not the first post on using NodeXL in Excel Macros in this forum I think it would be a real advancement if you could provide some information if this is possible.
After reading your post and finding my way through some other posts my only option seems to be to create a Visual Studio application, move all my code there and then I could use NodeXL. As this is quite a step up in complexity I'm not sure if I should so this.
Jun 29, 2014 at 9:23 PM
Hello, Christian:

The NodeXL Class Libraries are not COM compatible, and therefore cannot be used directly from VBA. I know of nothing that would prevent them from being made COM compatible, but given the time it would take to make the required project-level changes, provide default constructors for all COM-exposed classes (I'm pretty sure some are missing), and then test and document everything, that probably isn't going to happen anytime soon.

However, I can suggest a workaround that I used successfully to make the NodeXL Class Libraries available from a specific VBA project I once worked on. Here is what you might do:

1) In Visual Studio 2010 or 2013, create a C# or VB.NET Class Libraries project. Be sure to target .NET 4.0 or above.

2) Implement a single class that implements a single public method that performs your specific NodeXL task. Here is a sample method signature:
NodeXLWrapper.CreateNodeXLGraphImage(String pathToEdgeList, String pathWhereGraphImageShouldBeSaved)
Note that this is not a general purpose NodeXL wrapper. It performs only a specific task for a specific application. Also, you do not have to port any of your existing VBA code into it.

3) Import the assemblies from the NodeXL Class Libraries into your C# or VB.NET project, and use the NodeXL classes to implement your method. Your code will be C# or VB.NET, of course.

4) Make NodeXLWrapper COM compatible. That's easy, because it's just one class with one method.

5) Import the NodeXLWrapper type library into your VBA project.

6) Call your method on NodeXLWrapper from your VBA project.

That's my best suggestion.

-- Tony

Reference: "Exposing .NET Framework Components to COM",