1

I am trying to create a simple VB6 ActiveX exe and call it from Excel.

In VB6 I create an ActiveX DLL project called BigTrev, using all the default settings.

I create a MultiUse class called Trev with a single method containing no code

Public Sub HelloWorld() 
End Sub

I make a DLL and register it from the command line (VB6 also registers it for me but I did it using cmd as well anyway).

Then it Excel I create a reference to my DLL in a new workbook. It clearly has been registered because the Intellisense knows about Trev and HelloWorld.

Sub cats()

    Dim derek As BigTrev.Trev
    Set derek = New BigTrev.Trev
    derek.HelloWorld

End Sub

It compiles in Excel, when I step through it it fails in the second line, the Set one. Error message is "ActiveX component can't create object".

Why? I have done this or similar loads of times many years ago when VB6 was used widely, I am using Windows 7 now and I am an admin on my box.

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87
  • Fails how/with what error? – Alex K. Aug 19 '15 at 14:33
  • Sorry added to question, ActiveX component can't create object – Rob Sedgwick Aug 19 '15 at 14:35
  • Did you set the `Instancing` property of your class to `MultiUse`? – Bond Aug 19 '15 at 14:39
  • @Bond yes it is MultiUse – Rob Sedgwick Aug 19 '15 at 14:40
  • 32 or 64-bit version of Excel? – Bond Aug 19 '15 at 14:41
  • @Bond Excel is 64-bit – Rob Sedgwick Aug 19 '15 at 14:42
  • 2
    Native 64-bit apps cannot load 32-bit binaries. See [here](https://msdn.microsoft.com/en-us/library/office/ee691831(v=office.14).aspx#odc_office2010_Compatibility32bit64bit_ActiveXControlCOMAddinCompatibility). – Bond Aug 19 '15 at 14:44
  • Interesting, I created a VB6 exe and the same code worked so you could be right, although that article refers to ActiveX controls not DLLs. How can I use my DLL in Excel incdientally? – Rob Sedgwick Aug 19 '15 at 14:49
  • 2
    By ActiveX controls, they mean DLLs or OCXs that would get loaded into Excel's 64-bit process space. An "ActiveX Server" (EXE) should work fine as it runs in its own process space. – Bond Aug 19 '15 at 14:58
  • An ActiveX EXE and a DLL are both "ActiveX servers." The former is an out-of-process server while the latter is an in-process server. – Bob77 Aug 19 '15 at 16:33
  • @Bob77 - Of course. I was trying to recall the VB6 template name used to create an out-of-process server. I was thinking it was called `"ActiveX Server (EXE)"` but I may be wrong. – Bond Aug 19 '15 at 16:54
  • 1
    It's just "ActiveX EXE" and pretty easy to spot. – Bob77 Aug 19 '15 at 18:05
  • @Bond: In VB4, they didn't have DLL's, only EXE's, and they were called "OLE Servers." In VB5, the terminology changed to ActiveX EXE component and ActiveX DLL component. – BobRodes Aug 21 '15 at 07:02
  • @Bond: also, ActiveX controls are exclusively OCX's. DLL's are just called ActiveX DLL's. – BobRodes Aug 21 '15 at 07:09

1 Answers1

0

I would suggest registering the DLL (or EXE if that's the direction you've chosen) with the relevant regsvr32.exe. In this case, where you're registering a 32bit DLL for use in 64bit environment, use the one hiding out in c:\windows\syswow64.

Sadly, I don't have Excel (shock, horror) and the spreadsheet I do have (LibreOffice) is 32bit.

bugmagnet
  • 7,631
  • 8
  • 69
  • 131