Macro activating the spread sheet.

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 ?


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:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top