1 year ago

#345159

test-img

Daniel Möller

VBA runtime error 453 with declare statement

I have a c# dll that I created in Visual Studio, and I want to import a method from it in Excel VBA.

So, I use the Declare statement approach since I cannot register the library (company policies)

Private Declare PtrSafe Sub ExcelTest Lib "c:\CorrectPath\MyDll.dll" ()

Sub TestSub()
    Call ExcelTest
End Sub

While my DLL has the following:

namespace Default_Namespace_of_the_Project
{
    public static class ExcelTestClass //among many other classes, but this is the target one
    {
        public static void ExcelTest()
        {
            MessageBox.Show("Test Ok");
        }
    }
}

And yet, Excel keeps telling me I got a runtime error 453:

Specified DLL function not found

What is going on here? Why doesn't excel find the function? Is there a special attribute I need to add to the function? Does it need to be somewhere special in the DLL? How can I solve this?

c#

excel

vba

dll

dllimport

0 Answers

Your Answer

Accepted video resources