Software Support
Inserting a Single Field of Data into Excel (Above and Below)
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("GetSWDataAbove")] or [RUN("GetSWDataBelow")]
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.)
Row Below:
The following example subroutine for Excel shows how to insert data from WinWedge beneath the previously entered data. The code figures out where the bottom cell is each time it is called so the spreadsheet does not have to keep track of the bottom row with a memory variable. To use it enter the string: [RUN("GetSWDataBelow")] as the Field Postamble DDE Command after the last data field that you have defined.
Sub GetSWDataBelow()
Dim X As Long ' Dim all variables
Dim MyVar As Variant
Dim MyString As String
On Error Resume Next ' ignore errors
Application.DisplayAlerts = False ' turn off DDE warning messages
X = DDEInitiate("WinWedge", "COM1") ' connect to WinWedge
MyVar = DDERequest(X, "Field(1)") ' get Field(1)
DDETerminate X ' terminate the DDE link
MyString = MyVar(1) ' convert to a string
' find the row number of the last empty cell at the bottom of Col 1
X = Sheets("Sheet1").Cells(65000, 1).End(xlUp).Row + 1
Cells(X, 1).Value = MyString' put value in the last row
End Sub
Row Above:
Sub GetSWDataAbove()
Dim X As Long ' Dim all variables
Dim MyVar As Variant
Dim MyString As String
On Error Resume Next ' ignore errors
Application.DisplayAlerts = False ' turn off DDE warning messages
Sheets("Sheet1").Rows("1:1").Insert ' insert a row above row 1
X = DDEInitiate("WinWedge", "COM1") ' connect to WinWedge
MyVar = DDERequest(X, "Field(1)") ' get Field(1)
DDETerminate X ' terminate the DDE link
MyString = MyVar(1) ' convert to a string
Cells(1, 1).Value = MyString ' put value in A1
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 "GetSWDataAbove()" after each data record is received from your serial device. The "GetSWDataAbove" subroutine performs a DDERequest to WinWedge that returns the contents of FIELD(1) to a variable named "WedgeData". Data is inserted at the top of a row and moves all previous readings down in the sheet sort of like a strip chart recorder. The latest data is always in Cell A1 with all previous readings below it scrolling down as each new reading is inputted. The example above assumes that the open workbook contains a worksheet named Sheet1.
Need more help?Don't hesitate to call or email us with your questions! |
Technical Support: 215-496-0222Toll-Free: 1 (800) 722-6004 |