????? ????? ???? RealTimeData ?? Excel

?????? ????????? ?????? ?????????
???? ???????: 285339 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

??????

???? Microsoft Excel ???? ???? ??? ????? RTD ???? ?? ??????? ??????? ???? ????? ???? ???? ???? (COM) ?? ??? ??????? ?????? ????? ???????. ???? ??? ??????? ????? ??????? Visual Basic ?????? ???? RealTimeData ????????? ?????? ?????? RTD ?? Excel.

??????? ????

????? ???? ???? ????? RTD ???? ?????? ??????:
= RTD(ProgID,Server,String1,[String2],...)
??????? ?????? ProgID ???? "???? ???????" (ProgID) ????? RealTimeData. ????? ???? ???? ??? ??? ?????? ???? ??? ????? ???? RealTimeData; ?? ???? ??? ??????? ????? ????? ?? ?? ????? ??? ??? ???? RealTimeData ??????? ??????. ???? ???????? ???????? ?????? ?????? ???????? ??? ?????? RealTimeData; ???? ?? ?????? ????? ?? ??? ???????? ???? "???????"???? ????? ??? ???????"????? ???????." ?????? ????? ????? ??????. ??? ???? ??????? ??????? ???? ????????? ??? ???? RTD ???? ????? ??? ????? ?????? ??????? ??????:
= RTD("ExcelRTD.RTDFunctions",,"AAA", "10")

= RTD("ExcelRTD.RTDFunctions",,"AAA", "5")

= RTD("ExcelRTD.RTDFunctions",,"aaa", "5")
?? ??? ???? ??????? COM ?? ?????? RealTimeData ????????? ?? ?????? RTD ?? Excel ? ???? ??? ?? ???? ?????? ????? IRTDServer. ??? ?? ???? ?????? ?????? ???? ?????? IRTDServer:

ServerStart
??????? ????? ???? Excel ????? RTD ????? ??? ??????. ??? ??? ServerStart ????? 1 ??? ????? "?" ???? ????? "??" 0 ??? ?????. ??????? ?????? ?????? ServerStart ?? ???? ?? ????? ???? ???????? ???? RealTimeData ?????? Excel ??? ??? ????? ????????? ?? RealTimeData ??????.
ServerTerminate
??????? ????? ????? Excel ?? ??? ?????? RTD ?? ???? RealTimeData.
ConnectData
??????? ???? ????? Excel ????? RTD ???? ?? ???? RealTimeData.
DisconnectData
??????? ???? Excel ?? ????? ????? ????.
?????
??????? ?????? Excel ??? ?????? ?????? ???? ???? ??? ??? ??? ?? ?????? Excel ??????? ?? ???? RealTimeData.
RefreshData
??????? ????? ???? Excel ????? ??? ????????. ???? RefreshData ??? ?????? ?????? Excel ???? ????????? ?? ???? ?????? ??? ???????? ?????? ?? ???? ??????? ????? ?? ?????.

????? ???? RealTimeData ?????

???? ??????? ?????? ????? ????? ??????? ???? RealTimeData ?? Microsoft Excel 2002. ???? ??? ?????? ???? ???? ??? ?????? ?? 10 ????? ?? ???? ???. ???? ?????? ??? ??????? ???????. ???? ?? ???? ??????? ??????? ?????? AAA ? BBB CCC ????? ??? ????? ?? ????? ??????? ? ?????? ???? # VALUE! ??? ?????? RTD. ??????? ??????? ?????? ????? ???? ???? ????? ????? ???? ???????. ??? ?? ??? ??????? ??????? ?????????? ???? ??????? 1. ?? ???? ??? ????? ??????? ??????? ?????? ?????? # NUM! ??? ?????? RTD.
  1. ??? ????? ????? DLL ActiveX ???? ?? Visual Basic.
  2. ?? ??????? ??????? ???? "?????" ? ??? "????? ??????" ?????? ??? ????? Excel ?? ???? ??? ?????. ??? ???? ??????, ??? ??? ????????? ???????:
    • ??? ????? ?????? Microsoft Excel 12.0 Microsoft Office Excel 2007.
    • ??? ????? ?????? Microsoft Excel 11.0 Microsoft Office Excel 2003.
    • ??? ????? ?????? Microsoft Excel 10.0 Microsoft Excel 2002.
  3. ?? ??????? ??????? ???? ??? ????? ?????1. ????? ??? ??????? ??? ExcelRTD ?? ???? ??? ?????.
  4. ????? ????? ??? ??? ?????? ??????? Class1 ??? RTDFunctions. ?? ?????? ????????? ???????? ??????? ??? RTDFunctions:
    Option Explicit
    
    Implements IRtdServer  'Interface allows Excel to contact this RealTimeData server
    
    Private m_colTopics As Collection
        
    Private Function IRtdServer_ConnectData(ByVal TopicID As Long, Strings() As Variant, GetNewValues As Boolean) As Variant
        '** ConnectData is called whenever a new RTD topic is requested
        
        'Create a new topic class with the given TopicId and string and add it to the
        'm_colTopics collection
        Dim oTopic As New Topic
        m_colTopics.Add oTopic, CStr(TopicID)
        oTopic.TopicID = TopicID
        oTopic.TopicString = Strings(0)
        If UBound(Strings) >= 1 Then oTopic.SetIncrement Strings(1)
        
        'For this example, the initial value for a new topic is always 0
        IRtdServer_ConnectData = oTopic.TopicValue
        
        Debug.Print "ConnectData", TopicID
    End Function
    
    Private Sub IRtdServer_DisconnectData(ByVal TopicID As Long)
       '** DisconnectData is called whenever a specific topic is not longer needed
       
       'Remove the topic from the collection
       m_colTopics.Remove CStr(TopicID)
       
       Debug.Print "DisconnectData", TopicID
    End Sub
    
    Private Function IRtdServer_Heartbeat() As Long
        '** Called by Excel if the heartbeat interval has elapsed since the last time
        '   Excel was called with UpdateNotify.
        Debug.Print "HeartBeat"
    End Function
    
    Private Function IRtdServer_RefreshData(TopicCount As Long) As Variant()
        '** Called when Excel is requesting a refresh on topics. RefreshData will be called
        '   after an UpdateNotify has been issued by the server. This event should:
        '   - supply a value for TopicCount (number of topics to update)
        '   - return a two dimensional variant array containing the topic ids and the
        '     new values of each.
       
        Dim oTopic As Topic, n As Integer
        ReDim aUpdates(0 To 1, 0 To m_colTopics.Count - 1) As Variant
        For Each oTopic In m_colTopics
            oTopic.Update
            aUpdates(0, n) = oTopic.TopicID
            aUpdates(1, n) = oTopic.TopicValue
            n = n + 1
        Next
        TopicCount = m_colTopics.Count
        IRtdServer_RefreshData = aUpdates
       
       Debug.Print "RefreshData", TopicCount & " topics updated"
    End Function
    
    Private Function IRtdServer_ServerStart(ByVal CallbackObject As Excel.IRTDUpdateEvent) As Long
        '** ServerStart is called when the first RTD topic is requested
        
        Set oCallBack = CallbackObject
        Set m_colTopics = New Collection
        g_TimerID = SetTimer(0, 0, TIMER_INTERVAL, AddressOf TimerCallback)
        If g_TimerID > 0 Then IRtdServer_ServerStart = 1       'Any value <1 indicates failure.
        
        Debug.Print "ServerStart"
    End Function
    
    Private Sub IRtdServer_ServerTerminate()
        '** ServerTerminate is called when no more topics are needed by Excel.
        
        KillTimer 0, g_TimerID
    
        '** Cleanup any remaining topics. This is done here since 
        '   IRtdServer_DisconnectData is only called if a topic is disconnected 
        '   while the book is open. Items left in the collection when we terminate
        '   are those topics left running when the workbook was closed.
    
        Dim oTopic As Topic
        For Each oTopic In m_colTopics
            m_colTopics.Remove CStr(oTopic.TopicID)
            Set oTopic = Nothing
        Next
    
        Debug.Print "ServerTerminate"
      
    End Sub
    
    					
  5. ?? ??????? ??????? ???? ??? ????? ???? ????? ?????. ????? ??????? ??? ??? ?????? ??????? ??? ????? ?????? ??????? Instancing ??? ???. ?? ?????? ????????? ???????? ??????? ??? ???? ????? ????? ?????:
    Option Explicit
    
    Private m_TopicID As Long
    Private m_TopicString As String
    Private m_Value As Variant
    Private m_IncrementVal As Long
    
    Private Sub Class_Initialize()
        m_Value = 0
        m_IncrementVal = 1
    End Sub
    
    Friend Property Let TopicID(ID As Long)
        m_TopicID = ID
    End Property
    
    Friend Property Get TopicID() As Long
        TopicID = m_TopicID
    End Property
    
    Friend Property Let TopicString(s As String)
        s = UCase(s)
        If s = "AAA" Or s = "BBB" Or s = "CCC" Then
            m_TopicString = s
        Else
            m_Value = CVErr(xlErrValue) 'Return #VALUE if not one of the listed topics
        End If
    End Property
    
    Friend Sub Update()
        On Error Resume Next 'the next operation will fail if m_Value is an error (like #NUM or #VALUE)
        m_Value = m_Value + m_IncrementVal
    End Sub
    
    Friend Sub SetIncrement(v As Variant)
        On Error Resume Next
        m_IncrementVal = CLng(v)
        If Err <> 0 Then
            m_Value = CVErr(xlErrNum) 'Return #NUM if Increment value is not numeric
        End If
    End Sub
    
    Friend Property Get TopicValue() As Variant
        If Not (IsError(m_Value)) Then
            TopicValue = m_TopicString & ": " & m_Value
        Else
            TopicValue = m_Value
        End If
    End Property
    					
  6. ?? ??????? ??????? ??? ????? ?????? ???????. ?? ?????? ????????? ???????? ??????? ??? ???? ????? ?????:
    Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, _
    ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    
    Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
    
    Public Const TIMER_INTERVAL = 5000
    Public oCallBack As Excel.IRTDUpdateEvent
    Public g_TimerID As Long
    
    Public Sub TimerCallback(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
        oCallBack.UpdateNotify
    End Sub
    					
  7. ?? ??????? ???? ???? ??? ???? ExcelRTD.dll ????? ??????.

??????? ???? RTD ?? Excel

  1. ??? ????? "???? ????" ?? Microsoft Excel.
  2. ?? ?????? A1 ? ???? ?????? ??????? ??? ?? ???? ??????? ENTER:
    = RTD("ExcelRTD.RTDFunctions",,"AAA", 5)
    ???? ??????? ?????? "AAA: 0". ????? ??? ??? ???? ?????? ??? "AAA: 10" ??????? ??? 10 ???? ?????? ??? "AAA:15" ?????.

  3. ?? ?????? A2 ???? ?????? ??????? ?? ???? ????? ??????? ENTER:
    = RTD("ExcelRTD.RTDFunctions",,"BBB", 3)
    ???? ??????? ?????? "BBB: 0". ?? ??? ????? ?????? ???? ?????? ?????? 3.

  4. ?? ?????? A3 ???? ?????? ??????? ?? ???? ????? ??????? ENTER:
    = RTD("ExcelRTD.RTDFunctions",,"AAA", 5)
    ?????? ???? ??????? ?????? ?? ??????? ?????? A1 ??? ??? ?? ??? "???????" ????????? ?? A1.

  5. ?? ?????? A4, ???? ?????? ??????? ?? ???? ????? ???????:
    = RTD("ExcelRTD.RTDFunctions",,"AAA", 10)
    ???? ??????? ?????? "AAA: 0." ?? ???? ???????? ?????? ???? ?????? ??? ???? ??????? ??????. ???? ?? ???? ??????? ??? ??????? ?? ??????? ?????? A1 ?? A3 ??? ?????? ???????? ???? ?? ??????? ??? ?????? ???.
?????? ??? ??? ????? ???????? ?????? RTD ???? ?? ??????? ??????? ?? ?? Excel ???????? ????? ??? ??????? ?? ??????. ?????? RTD ??????? ???? ????? ???????? ?? IDE Visual Basic.

????? ?? ??? ???????:
  1. ????? Microsoft Excel ???????? ??? ??????? ?? Visual Basic.
  2. ???? F5 ?????? ??????. ??? ??? ???? ?????? ????? ??????? ???? ??? ????? ????? ?????? ????????? ?? ?????? ???????? ?????? ??????.
  3. ???? ?? ??? ?????? ?????? ?? Visual Basic. ??? ????? ????? ?? ??????? ? ??? ??? ????? ??????? ??? ??????? ?????? ?????? ?? Visual Basic ??????? ????????? ???? ??? ????? ?????? ??????.
?????? ?????? ??????? DisconnectData

????? ???? Excel ????? ??? ???? RTD ? ???? ?????? ????? DisconnectData ??? ?? ??? ????? ????? (??? ???? ??????? ??? ??? ?? ??? RTD ???? ?? ????). ??? ???? Excel ?? ???????? DisconnectData ??? ?? ????? ????? RTD ????? ??? ????? ?????? ?? ????? Excel; ????? ?? ???? ???? Excel ?????? ServerTerminate. ??? ????? ???? RTD ??? ??? ?? ?? ???????? ????? ???????? ?? ?????? ???? ??? ??? ????? ServerTerminate.

(c) ??? ???? Microsoft ???? ???? ?????. ????????? ??? Lori B. Turner ? Microsoft Corporation.

?????

?????? ??? ??????? ??????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
284883?????? RTD ??? ????? ??????? ????? ??? ?????? ?????? ?? Excel

???????

???? ???????: 285339 - ????? ??? ??????: 10/???? ?????/1428 - ??????: 5.1
????? ???
  • Microsoft Office Excel 2007
  • Microsoft Office Excel 2003
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Visual Basic 6.0 Professional Edition
????? ??????: 
kbmt kbexpertisebeginner kbautomation kbhowto KB285339 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????285339

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com