Download WINWEDGE USERS MANUAL

Transcript
' this macro runs automatically when you close the spreadsheet
Sub Auto_Close()
' activate sheet1
Sheets("Sheet1").Activate
ActiveWorkbook.SetLinkOnData "WinWedge|" & MyPort & "!RecordNumber", ""
' shut down the SetLinkOnData function by assigning it an empty string to the macro name
' remove the dde link from R1C50
Sheets("Sheet1").Cells(1, 50).Formula = ""
' ignore errors
On Error Resume Next
Chan = DDEInitiate("WinWedge", MyPort) ' open a dde link with WinWedge
' tell WinWedge to quit
DDEExecute Chan, "[Appexit]"
' terminate the DDE link
DDETerminate Chan
End Sub
Sub GetSWData()
ColPtr = 1
' point to the next row down
RowPtr = RowPtr + 1
' If this is the first time through then initialize RowPointer to point to Row 1 and
' ColPointer to point to Column 1 - i.e. collect data into column 1 starting in Row 1
' initiate DDE link with WinWedge
Chan = DDEInitiate("WinWedge", MyPort)
MyVariantArray = DDERequest(Chan, "Field(1)") ' get Field(1) from WinWedge
' convert to a string
MyString$ = MyVariantArray(1)
' The DDERequest function in Excel returns a variant array data type. This is a peculiarity of
Excel,
' the return type should be a string data type. The above line fixes the Excel "inconsistency"
and
' converts the variant array to a string by assigning element 1 of the variant array to a string
' Add your code here to do something with the data maybe?
' or possibly send a command back to WinWedge as in the following line
' DDEExecute chan, "[Beep]" ' send a beep command to WinWedge
Sheets("Sheet1").Cells(RowPtr, ColPtr).Formula = MyString$
' the above line writes the data to cell address: (RowPtr,ColPtr) in Sheet1
' terminate the dde link
DDETerminate Chan
End Sub
79