How to use Winsock library or Mswinsck.ocx into VBA excel in windows 10 laptop? RRS feed

  • Question

  • I need to communicate with an instrument that use a TCP/IP communication, and I want to use VBA in excel with windows 10 laptop. is there anyone who can show me a good example that send and receive strings? 
    I tried to use MSWISCK.ocx but its functions and sub's are not familiar to me. I have added MSWISCK.ocx in tool--> references, Every time when I tried to run the following code, "ActiveX component cant create object" error is popping up.

    Dim Winsock1 As Winsock 'Object type definition

    Sub Init()
        Set Winsock1 = New Winsock 'Object initialization
        Winsock1.RemoteHost = ""
        Winsock1.RemotePort = "2049"
    End Sub

    'Callback handler
    Private Sub Winsock1_Connect()
        MsgBox "Winsock1::Connect"
    End Sub

    One more information, the communication uses an IP address and port ex. IP=, port=2049.

    Wednesday, October 31, 2018 6:46 AM

All replies

  • Last time I used this was on a Windows Vista 32-bit computer.  I later upgraded to Win 7 32-bit.  I don't think this works on 64-bit Windows.  But you can try to add to  C:\Windows\SysWOW64\ .

    Then go to command prompt and run as administrator and type in regsvr32 c:\windows\syswow64\MSWINSCK.OCX. It is caps sensitive so if your MSWINSCK.OCX is lowercase like this: mswinsck.ocx then you have to put mswinsck.ocx with lowercase when typing into the command prompt.

    Wednesday, October 31, 2018 11:48 AM
  • Thanks Mogulman for the information.

    I registered MSWINSCK.OCX in C:\Window\SysWOW64\, still I am facing the same error "ActiveX component cant create object"

    Thursday, November 1, 2018 9:53 AM
  • I suspect it doesn't work on 64-bit Windows.  If it was me I'd do this in C#.  Probably create a C# .NET COM DLL I could call from VBA. 
    Thursday, November 1, 2018 10:34 AM