Software Support

Requesting data from WinWedge using a VBA subroutine

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("GetSWData")]

Excel Instructions

Create or edit a macro module in Excel and enter the following code in the module:
(To create a new module click on Insert > Module from the Menus in the Visual Basic Editor Window.)

Sub GetSWData()

   Dim R As Long
   Dim X As Long
   Dim Chan As Long
   Dim NumFields As Long
   Dim vDat As Variant
   Dim sDat As String

   ' find the next empty row in Column A
   R = Thisworkbook.Sheets("Sheet1").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. If more than one field is specified, each field is
   ' placed in its own column.

   ' How many data fields are we retrieving from WinWedge?
   NumFields = 1

   ' Loop through all data fields defined in the Wedge
   For X = 1 To NumFields

      ' Request the data from each field in the wedge
      vDat = DDERequest(Chan, "Field(" & Cstr(X) & ")")

      ' Convert the data from a variant array data type to a string 
      sDat = vDat(1)

      ' Place the data in cell location Row = R, Column = X
      Thisworkbook.Sheets("Sheet1").Cells(R, X).Value = sDat

   Next

   DDETerminate Chan ' Close the DDE channel

   ' Insert a date/time stamp in the sheet in the same row as the data 
   Thisworkbook.Sheets("Sheet1").Cells(R, NumFields + 1).Value = Now

End Sub

The example above sets up WinWedge to issue a DDE command consisting of the Excel "RUN" command forcing Excel to run the subroutine "GetSWData()" after each data record is received from your serial device. The "GetSWData" subroutine performs a DDERequest to WinWedge that returns the contents of FIELD(1) to a variable named "WedgeData". The data is then assigned to a cell in "Sheet1" and a pointer variable is updated so that the next input will be written to the cell directly below the last input. The example above assumes that the open workbook contains a worksheet named Sheet1.

Categories: Macro / Code Sample, Microsoft Excel, WinWedge
Last Updated: 2011.07.12
Need more help?

Don't hesitate to call or email us with your questions!

Technical Support: 215-496-0222

Toll-Free: 1 (800) 722-6004
Skype: taltech1
Email: support@TALtech.com
Our office is open 9AM - 5PM Monday Through Friday (E.S.T.)