Note: For a list of DDE commands, check out the support article listing WinWedge DDE Commands.
WinWedge makes it very easy for Excel to communicate with the device. This isn’t limited to simply logging data from the device to Excel, but WinWedge also enables Excel to send data directly from VBA using WinWedge’s “SENDOUT” and “SEND” DDE Commands
Sending a Command to the Device using SENDOUT DDE Command
The following code allows you to send any command to your device. In this example, we’re sending four characters: an ASCII 27 (an ESC character), a capital ‘P’, and a carriage return and line feed characters (ASCII 13 and 10).
Function SendCommand() Dim Chan As Long Chan = DDEInitiate("WinWedge", "COM1") DDEExecute Chan, "[SENDOUT(27,'P',13,10)]" DDETerminate Chan End Function
Sending a String to the Device using SEND DDE Command
If you need to send an entire string to the device, you can use the following code:
Function SendString (StringVar$) Dim Chan As Long Chan = DDEInitiate("WinWedge", "Com1") DDEExecute Chan, "[SEND(" + StringVar$ + ")]" DDETerminate Chan' terminate the link End Function
This code can even be used to send an entire table or query out the serial port:
Sub SendQuery() Dim chan, MyDb, MyQuery, strSend 'set database Set MyDb = CurrentDb() 'open a table or query that holds the data you wish to send Set MyQuery = MyDb.OpenRecordset("Deliveries") 'Open DDE Channel to WinWedge chan = DDEInitiate("WinWedge", "COM2") 'point to first record in the table/query MyQuery.MoveFirst Do strSend = "" 'reset string between records 'Generate string to send For i = 0 To MyQuery.Fields.Count - 1 strSend = strSend & MyQuery.Fields(i) & "," Next 'trim off last comma and replace it with CR/LF strSend = Left(strSend, Len(strSend) - 1) & vbCrLf 'send string DDEExecute chan, "[SEND(" + strSend + ")]" MyQuery.MoveNext 'point to next record in the query Loop Until MyQuery.EOF 'while (we have not reached the end of the table/query) quit: 'close DDE channel and clean up DDETerminate chan Set db = Nothing Set chan = Nothing End Sub