Sub excelAutoEntry()
On Error Resume Next
Dim haWin32, haScript As Object
Dim strInput As String

'create objects open HyperACCESS
Set haWin32 = CreateObject("HAWin32")
Set haScript = haWin32.haInitialize("excelAutoEntry")

'connect HyperACCESS
haScript.haSizeHyperACCESS 4
haScript.haOpenSession "session.HAW"
haScript.haConnectSession 0
haScript.haWaitForConnection 1, 100000

'add column headers
ActiveCell.Value = "Time"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Value1"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Value2"
ActiveCell.Offset(1, -2).Select

firstFlag = True

'loop while connected
While haScript.haGetConnectionStatus = 1
strInput = haScript.haGetInput(0, -1, 50, 1000)
If strInput <> "" Then
'clean up and parse data
strInput = Replace(Replace(strInput, Chr(10), ""), Chr(13), "")
Data = Split(strInput, ",")
strDate = Data(0)
strVal1 = Data(1)
strVal2 = Data(2)

'write data to spreadsheet
ActiveCell.Value = strDate
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = strVal1
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = strVal2
ActiveCell.Offset(1, -2).Select
strInput = ""
End If


End Sub

Sub disconnectHaw()
Set haWin32 = GetObject(, "HAWin32")
Set haScript = haWin32.haInitialize("disconnect")

End Sub

To execute this sample save the above subroutines in a macro in your excel spreadsheet. Run the excelAutoEntry subroutine to start capturing data, run the disconnectHaw subroutine to stop capturing data.

Return to sample script index