user3320758
user3320758

Reputation: 31

Socket connection using Excel VBA

I have a VB.NET application that successfully sends a string to the specified IP address and port.

Public Sub BroadcastData(ByVal toSend As String, ByVal PortToSendTo As Long)
    Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
    Dim sendBUF As Byte() = Encoding.ASCII.GetBytes(toSend)
    Dim ep As New IPEndPoint(MainForm.IPToBroadcastTo, PortToSendTo)
    s.SendTo(sendBUF, ep)
    System.Diagnostics.Debug.WriteLine(s.SendTo(sendBUF, ep))
End Sub

The IPToBroadcstTo is the IPaddress of a remote computer on the local network.

On this remote computer I can receive this string and do what I want with it using VB.NET.

I would to receive the string in Excel and write it to a cell.

Upvotes: 3

Views: 19084

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27342

The code you posted is VB.NET. Excel uses VBA which although it shares some common syntax is a completely different language with a reduced set of libraries.

For example there is no Socket or IPEndPoint class in VBA.

So in short the answer is that you can't use that code to open a socket in Excel.

Have a look at the Winsock control or

Maybe you could write a .NET assembly and expose it through COM interop to allow this to be used in Excel.

Upvotes: 1

Related Questions