1

This is my c# library I from which dll is generated, Also have enabled the COM visiblity in Property -> App,Build

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;

    namespace howto_dll_for_excel
    {
        [ComVisible(true)]
        [ClassInterface(ClassInterfaceType.None)]
        [ProgId("howto_dll_for_excel.CSharpTools")]
        public class CSharpTools
        {
            [ComVisible(true)]
            public string AddBrackets(string value)
            {
                return "[" + value + "]";
            }
        }
    }

I am trying to access this dll in MS excel using vba as active X

I added the reference of the dll to this vba code,then created a button and this is the macro definition

Sub Button1_Click()
Dim sheet As Worksheet
Dim tools As howto_dll_for_excel.CSharpTools
Dim value As String
Dim result As String
Set sheet = ActiveSheet
value = sheet.Cells(1, 1)
tools = CreateObject("howto_dll_for_excel.CSharpTools")
End Sub

My problem is,

Here the first access of the project howto_dll_for_excel automatically lists the CSharpTools class,

but in the last CreateObject Statement ,it is not listing,even if I type it manually prompts error

"Compile error: Method or data member not found" .

7
  • As far as I remember, CreateObject expects a string as input, try CreateObject("howto_dll_for_excel.CSharpTools") Commented Mar 26, 2015 at 6:55
  • Yup, he missed the quotes. Commented Mar 26, 2015 at 7:55
  • thanks for the reply,but that also doesnt work Commented Mar 26, 2015 at 13:12
  • @keerthee do you get the same error or a different error after adding the quotes? Commented Mar 26, 2015 at 13:20
  • Check whether the following registry key exists: HKEY_CLASSES_ROOT\howto_dll_for_excel.CSharpTools . If not then you'll have to register your DLL: regsvr32 c:\path.to\mydll.dll and then try again Commented Mar 26, 2015 at 15:26

1 Answer 1

1

The real problem was that, the dll was 32 bit and the excel was 64 bit version

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.