Skip to main content

Calling a .NET DLL Function from VBA

Recently i had to call .NET code from my VBA Macro in order to do something not available out of the box using VBA. i searched a lot of content on the web and found this wonderful web page
http://www.geeksengine.com/article/create-dll.html

The article clearly explains how to create a dll and reference it in VBA.
There were a some issues I hit upon while following the instructions mentioned in the link
1. In my code I had the following line of code
    Set f1 = New myplugin.Class1

The VBA compiler complained invalid use of New Keyword. I then modified my code to the following based on a colleague's suggestion
Set f1 = CreateObject("myplugin.Class1")
and then it worked fine.


2. On trying to create an instance of the .NET class in my VBA code
When distributing the dll by using following link, I hit upon an issue
http://www.geeksengine.com/article/register-dll.html

I was getting the following error on target machines
RegAsm: error RA0000 : Unable to locate input assembly 'myplugin.dll' or one of its dependencies

I searched the web again to find a solution to this error and found the following link that helped me out
http://serverfault.com/questions/253096/how-to-register-a-dll-using-powershell-without-regasm

The path to paste the dll and tlb files was C:\Windows\SysWOW64 since target machines were 64-bit .

Hope this helps

Comments

Popular posts from this blog

A simple customization in MPOS (Blank Operation) with AX7

Hi All, I recently had to add a Blank Operation to Modern POS (MPOS) to open a url from MPOS. Blank Operation as you may already be aware enable you to extend Microsoft Dynamics Retail for POS by adding custom logic that can be triggered from the Retail POS Register buttons. The way to implement Blank Operations in MPOS  is different from Enterprise POS as MPOS is a modern app as compared to EPOS which is a windows forms based app. So lets explore a very simple customization i.e. we want to open a URL on triggering a button from MPOS. 1. We would need to start with AX to add a button to the layout of MPOS. If you do not want to disturb the standard layouts its better to copy one of the existing layouts and then modify it using the designer. Please note the designer only opens in Internet Explorer so it will save you time by not trying to open it in other browsers e.g Chrome 2. Next we need to add this layout to the Store where we intend to use it, in

Hyper-V VM 100% disk utilization

I was facing a persistent issue of 100% disk utilization on starting any VM in my Hyper-V. The below link helped me to resolve it https://social.technet.microsoft.com/Forums/office/en-US/2b184f22-ea8c-4bc3-9f64-8b46eeaeef61/hyperv-host-disk-usage-at-100?forum=w8itprovirt