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

IPToBroadcstTo is the IP address of the remote computer on the local network.

On this remote computer, I can get this line and do whatever I want with it using VB.NET.

I would like to get a row in Excel and write it to a cell.

+3
source share
1 answer

You have submitted the VB.NET code. Excel uses VBA, which although it shares some common syntax, is a completely different language with a reduced set of libraries.

For example, in VBA there is no class Socketor IPEndPoint.

In short, the answer is that you cannot use this code to open a socket in Excel.

Winsock

, .NET COM-, Excel.

+1

All Articles