写IFIX 实时数据到Excel

[复制链接]
查看1321 | 回复0 | 2011-3-24 12:11:00 | 显示全部楼层 |阅读模式
Dynamics data into an Excel worksheet: 下面的程序可以让你把FIX数据写到EXCEL工作表中 ' Declare necessary API routines: 定义必要的API Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Sub DetectExcel() ' Procedure dectects a running Excel and registers it.生成运行一EXCEL工作表并保存之 Const WM_USER = 1024 Dim hwnd As Long ' If Excel is running this API call returns its handle.如果Excel运行这个API调用返回其句柄, hwnd = FindWindow("XLMAIN", 0) If hwnd = 0 Then ' 0 means Excel not running.0表示EXCEL没有运行 Exit Sub Else ' Excel is running so use the SendMessage API function to enter it in the Running Object Table. EXCEL运行就用API的SendMessage功能发送到运行的工作表中 SendMessage hwnd, WM_USER + 18, 0, 0 End If End Sub Private Sub CommandButton2_Click() Dim msexcel As Excel.Application Set msexcel = CreateObject("Excel.Application") With msexcel .Visible = True .Workbooks.Open "d:\fix32\Test1.xls", , False End With End Sub Private Sub CommandButton3_Click() Dim MyXL As Object ' Variable to hold reference to Microsoft Excel. Dim ExcelWasNotRunning As Boolean ' Flag for final release. ' Test to see if there is a copy of Microsoft Excel already running. On Error Resume Next ' Defer error trapping. ' Getobject function called without the first argument returns a reference to an instance of the application. If the application isn't running, an error occurs. Note the comma used as the first argument placeholder. Set MyXL = GetObject(, "Excel.Application") If Err.Number <> 0 Then ExcelWasNotRunning = True Err.Clear ' Clear Err object in case error occurred. ' Check for Excel. If Excel is running,enter it into the Running Object table. DetectExcel 'Set the object variable to reference the file you want to see. Set MyXL = GetObject("d:\fix32\test1.XLS") ' Show Microsoft Excel through its Application property. Then show the actual window containing the file using the Windows collection of the MyXL object reference. MyXL.Application.Visible = True MyXL.Parent.Windows(1).Visible = True ' Do manipulations of your file here. With MyXL.Application .ActiveWorkbook.ActiveSheet.Select .Goto reference:=.Range("D4") End With ' If this copy of Microsoft Excel was not already running when you started, close it using the Application property's Quit method. Note that when you try to quit Microsoft Excel, the Microsoft Excel title bar blinks and Microsoft Excel displays a message asking if you want to save any loaded files. If ExcelWasNotRunning = True Then MyXL.Application.Quit End If Set MyXL = Nothing ' Release reference to the application and spreadsheet. End Sub
您需要登录后才可以回帖 登录 | 注册哦

本版积分规则