3

I have written two addins , 1 for excel and 1 for word. However these addins have a lot of duplicates: Database handling, file handling,array handling which I would like to update 1 place instead of two.

We do have access to sharepoint, and could get access to visual studio. The thing is that people like to use file explorer and find the correct word or excel file, then open it then press a button inside the application which then should do things with the active document.

This is why we haven't written it as a .Net application yet, because that requires that people browse for the file inside the .NET application uless I am mistaken.

Is it possible to make an Addin which works both excel and word, or a dll? AnAnother important thing is that it should be easy to roll out a new version to the user, like stored on a network drive or similar.

Community
  • 1
  • 1
skatun
  • 856
  • 4
  • 17
  • 36
  • 2
    Make a COM visible class library in C# then call it in your Add-in code. You can still use the file browsers withing Word and Excel but call out to the .net class to do the shared logic. E.g. http://stackoverflow.com/questions/19954001/calling-a-net-library-method-from-vba – Robin Mackenzie Mar 07 '17 at 12:07
  • 1
    Your question is quite broad. I think a good point to start might be [Create VSTO Add-ins for Office by using Visual Studio](https://msdn.microsoft.com/en-us/library/jj620922.aspx). Code that is shared by different applications/addins can be outsourced into a dll. And rollout could be done via GPO. – Pᴇʜ Mar 07 '17 at 12:08

1 Answers1

1

Yes it is possible

The Hard Way

You can create a .Net DLL and call it from VBA. In visual studio a lot of people use Unmannaged Exports by Robert Giesecke to create DLLs that don't need to be registered (that way the DLL can be shipped with your document, and as long as it can be found you can use it).

Alternatively you might be able to do it manually as shown here by Hans Passant.

The Easy Way

Once the DLL is created you can declare it in a VBA module the same way you declare any other DLL for Late Binding and then call it from your code.

OR if you're happy to create the DLL and add it as a reference (possibly less portable) you can make it COM visible and register it for COM Interop in Visual Studio; this is probably the easiest way to go because you can then use Early Binding.

This is a walk through that might help: http://www.geeksengine.com/article/create-dll.html


But if you want to store the DLL on a network drive, well it might be that you really want to look at doing it the 'hard way', in which case look here: https://stackoverflow.com/a/5934745/3451115 and here: https://msdn.microsoft.com/en-us/library/bb687915.aspx

SlowLearner
  • 3,086
  • 24
  • 54