Share excel workbook containing dll

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,907
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This site shows how to create a dll in Visual Studio:

Code:
https://www.youtube.com/watch?v=SoO_uUPfHOI&t=472s


Here is the C# code:

Code:
using System.Runtime.InteropServices;
namespace SimpleCalc
{
    [ComVisible(true)]

    public class Calculation {
        private int numone = 0;
        private int numtwo = 0;

        public void SetNumOne(int number) {
            numone = number;
        }
        public void SetNumTwo(int number)
        {
            numtwo = number;
        }
        public int addnumbers() {
            return numone + numtwo;
        }
    }
}


This is the VBA code:

Code:
Option Explicit

Sub Test()

    Dim obj As New SimpleCalc.Calculation
    
    obj.setnumone (10)
    
    obj.setnumtwo (20)
    
    Debug.Print obj.addnumbers()
    
End Sub


In order for the VBA code to run, a reference to SimpleCalc must be added in the VB editor.

The C# code is saved on my PC and everything works as expected.

My question is if I send this to another person, what would they have to do to make the VBA work? I assume references "do not travel" with the workbook.

Would I need to send the C# code as well and if so, where should that be saved?

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
References do travel with the workbook, but the referenced files do not. You would have to send them the dll as well, and they would need to register it.
 
Upvote 0
References do travel with the workbook, but the referenced files do not. You would have to send them the dll as well, and they would need to register it.
Thanks for the info.

The reason for creating the dll is (as far as I'm aware) that it creates an extra layer of security to the standard VBA protection of the code.

But if you need to send the dll file in order for the workbook to function, doesn't that defeat the whole idea of security?
 
Upvote 0
No, since a dll is a compiled executable, not source code.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top