MeltManBob
New Member
- Joined
- Apr 3, 2013
- Messages
- 7
Hey guys I've messed with VBA a bit in the past but never to connect to a site to get information or using an API or COM. I'm trying to get historical Forex data from FXCM. They have a Forexconnect API and COM, both of which I've installed as instructed and enabled the fxcore2_com reference in the VBA editor. The COM comes with sample excel files and the one I'm trying to use and having problems with is the Login.xls. This is the code in that file:
When I run the Login routine I get an automation error. When put the cursor in front of "Public Sub Login()" and hit the play button, I get:
Run-time error '-2147024894 (80070002)':
Automation error
The system cannot find the file specified
I get this same error when I choose "run to cursor" and the cursor is placed in front of "If LastSessionStatus = SessionStatusCode_Connected Then"
Can anyone tell me what is going on with this?
Code:
Option Explicit
Dim transport As transport
Dim WithEvents session As session
Dim LastSessionStatus As fxcore2_com.SessionStatusCode
Public Sub Login()
Call CheckState
If LastSessionStatus = SessionStatusCode_Connected Then
Range("Info").Value = "Please logout at the first"
Exit Sub
End If
'force login
If Range("Login").Value = "" Or Range("Password").Value = "" Then
Range("Info").Value = "Please provide login and password"
Exit Sub
End If
Call session.Login(Range("Login").Value, Range("Password").Value, Range("URL").Value, Range("Connection").Value)
Range("Info").Value = "Logged in..."
End Sub
Public Sub Logout()
If LastSessionStatus <> SessionStatusCode_Connected Then
Range("Info").Value = "Please login at the first"
Exit Sub
End If
Call session.Logout
End Sub
Private Sub Worksheet_Activate()
On Error GoTo Catch
Call CheckState
Exit Sub
Catch:
MsgBox Err.Description
End Sub
Private Sub CheckState()
If transport Is Nothing Then
Set transport = CreateObject("fxcore2.com.Transport")
'create session
Set session = transport.createSession()
Range("Status").Value = GetStatusName(LastSessionStatus)
End If
End Sub
Private Sub Worksheet_Deactivate()
On Error Resume Next
Set session = Nothing
Set transport = Nothing
End Sub
Private Sub session_SessionStatusChanged(ByVal status As SessionStatusCode)
On Error GoTo Catch
Range("Status").Value = GetStatusName(status)
Range("Info").Value = ""
LastSessionStatus = status
Exit Sub
Catch:
MsgBox Err.Description
End Sub
Private Sub session_SessionStatusLoginError(ByVal error As String)
Range("Info").Value = error
End Sub
Private Function GetStatusName(status As SessionStatusCode)
Select Case status
Case SessionStatusCode_Connected
GetStatusName = "connected"
Case SessionStatusCode_Disconnected
GetStatusName = "disconnected"
Case SessionStatusCode_Connecting
GetStatusName = "connecting"
Case SessionStatusCode_TradingSessionRequested
GetStatusName = "trading session requested"
Case SessionStatusCode_Disconnecting
GetStatusName = "disconnecting"
Case SessionStatusCode_SessionLost
GetStatusName = "session lost"
Case SessionStatusCode_PriceSessionReconnecting
GetStatusName = "price session reconnecting"
Case SessionStatusCode_Unknown
GetStatusName = "unknown"
Case Else
GetStatusName = CStr(status)
End Select
End Function
When I run the Login routine I get an automation error. When put the cursor in front of "Public Sub Login()" and hit the play button, I get:
Run-time error '-2147024894 (80070002)':
Automation error
The system cannot find the file specified
I get this same error when I choose "run to cursor" and the cursor is placed in front of "If LastSessionStatus = SessionStatusCode_Connected Then"
Can anyone tell me what is going on with this?