newbie_vba
New Member
- Joined
- Mar 24, 2009
- Messages
- 1
Hi There,
I have written a Public Function in Excel VBA. I have incorporated into a spread sheet that was already running in a non-intrusive way ( minimised). When I introduced following function which is run every second by another Macro .. it caused the control to switch to the spread sheet ... and removing the function resolved the issue.
I am thinking is it Application.Run that would have caused it ?
I have written a Public Function in Excel VBA. I have incorporated into a spread sheet that was already running in a non-intrusive way ( minimised). When I introduced following function which is run every second by another Macro .. it caused the control to switch to the spread sheet ... and removing the function resolved the issue.
I am thinking is it Application.Run that would have caused it ?
Code:
Public Function Contrib(source As String, instrCode As String, ByVal FieldNameArrayVar As Range, ByVal FieldValueArrayVar As Range, Optional RtMode As String = "") As String
Const lRecType As String = "15910"
Dim FieldNameArray As Variant
Dim FieldValueArray As Variant
Dim bBidFound As Boolean
Dim bAskFound As Boolean
Dim iBID As Double
Dim iAsk As Double
Dim getBid As Double
Dim getASk As Double
Dim askbidPrecision As Double
Dim ret As String
On Error GoTo ErrHandler
Open "C:\temp\publish.log" For Append As #1
askbidPrecision = 0.00001
FieldNameArray = FieldNameArrayVar
FieldValueArray = FieldValueArrayVar
'Search for Bid or ask
bBidFound = False
bAskFound = False
i = 1
For i = LBound(FieldNameArray, 2) To UBound(FieldNameArray, 2)
If UCase(FieldNameArray(1, i)) = "BID" Then
bBidFound = True
iBID = CDbl(FieldValueArray(1, i))
End If
If UCase(FieldNameArray(1, i)) = "ASK" Then
bAskFound = True
iAsk = CDbl(FieldValueArray(1, i))
End If
Next i
If (bBidFound = False And bAskFound = False) Then
Print #1, "No bid or Ask found in the Fields being published."
End If
getBid = CDbl(Application.Run("RtGet", source, instrCode, "BID"))
getASk = CDbl(Application.Run("RtGet", source, instrCode, "ASK"))
If ((Abs(iBID - getBid) < askbidPrecision) And (Abs(iAsk - getASk) < askbidPrecision)) Then
Print #1, Str$(Now) & "NotPublishing for" & instrCode & "due to Throttling Old Bid And ask : " & Str(getBid) & Str(getASk) & _
"New Bid and Ask " & Str(iBID) & Str(iAsk)
ret = "Sent at" & Format(Application.Run("RtGet", source, instrCode, "VALUE_DATE"), "hh:mm:ss")
Else
ret = Application.Run("RtContribute", source, instrCode, FieldNameArray, FieldValueArray, RtMode)
Print #1, Str$(Now) & "Publishing New Price for" & instrCode & "Old Bid And ask : " & Str(getBid) & Str(getASk) & _
"New Bid and Ask " & Str(iBID) & Str(iAsk) & " Publish Time :" & ret
End If
Close #1
Contrib = ret
ErrHandler:
If Err.Number <> 0 Then
Print #1, Str(Err.Number) & Err.Description
Contrib = Err.Description
Close #1
End If
End Function
Last edited by a moderator: