Collecting Multiple Consecutive Fields of Data into Excel

This example demonstrates how to collect multiple successive data fields from WinWedge. While this example only shows 4 fields of data being requested, you can easily modify this example to collect up to 40 fields of data by simply changing the NumFields variable.

WinWedge DDE Server Settings

Remember to set WinWedge up in DDE Server Mode! Click here.

DDE Application Name: Excel
DDE Topic: System
DDE Command: [RUN(“GetConsecutiveFields”)]

Excel Instructions

Create or edit a macro module in Excel and enter the following code in the module. If your device only has a single field of data, a slimmed down version located at the bottom of the page can be found by clicking here. (To create a new module click on Insert > Module from the Menus in the Visual Basic Editor Window.)

Sub GetConsecutiveFields()

    'Dimension all variables
    Dim R As Long, X As Long, Chan As Long, NumFields As Long, vDat As Variant, sDat As String
   
    ' Find the next empty row in Column A
    R = ThisWorkbook.Sheets(1).Cells(65000, 1).End(xlUp).Row + 1
   
    ' Establish DDE link to WinWedge on COM1
    Chan = DDEInitiate("WinWedge", "COM1")
   
    ' WinWedge can be configured to parse data into more than one data field.
    ' The following code demonstrates how to retrieve one or more data fields.
    ' Each field is placed in its own column followed by an optional date/time stamp.
   
    NumFields = 4 ' How many data fields are we retrieving from WinWedge?
   
    For X = 1 To NumFields                                      ' Loop through each field
        vDat = DDERequest(Chan, "Field(" & CStr(X) & ")")       ' Request data from WinWedge
        sDat = vDat(1)                                          ' Convert to a string
        ThisWorkbook.Sheets(1).Cells(R, X).Value = sDat  ' Place the data in a cell
    Next                                                        ' Continue Loop
   
    DDETerminate Chan ' Close the DDE channel
       
    ' IF YOU WOULD LIKE TO DO SOMETHING WITH THE DATA, YOUR CODE WOULD GO HERE
   
    ' You can also insert a date/time stamp after the last field by uncommenting the following line.
    ' ThisWorkbook.Sheets(1).Cells(R, NumFields + 1).Value = Now

End Sub

Contact Us