Excel DDE服务器将RTD数据传输到另一个应用程序

时间:2018-07-21 20:53:47

标签: excel vba excel-vba excel-formula

我有一个excel文件,可将数据从一个应用程序提取并转发到另一个应用程序。但是正向方法是将数据写入CSV文件。但是我想通过DDE方法转发数据。但是我不知道如何制作一个Excel文件作为DDE服务器。任何人都可以帮助我制作excel文件作为DDE服务器。文件下载链接-Excel File Download Link,这是CSV文件生成代码-

Dim fs As Object, a As Object, C As Integer, i As Integer, R As Integer, S As String, t As Variant, CellValue As String
'Create a file object for writing
Set fs = CreateObject("Scripting.FileSystemObject")
If Range("B2") = "" Then
On Error Resume Next
MkDir ("C:\RT")                'This will create a folder RT in C Drive.
FileName = "C:\RT\MyCSVNest.txt"   'This file is used to write quotes
Else
FileName = Range("B2") + "\MyCSVNest.txt"   'This file is used to write quotes
End If

Set a = fs.CreateTextFile(FileName, True) 'Here we create the file MyCSV.csv
MyBook.Sheets("Nest").Select 'Selects sheet containing quotations


For R = 7 To Range("A65536").End(xlUp).Row
    S = Format(Date, "dd/mm/yyyy") & ","
    C = 1
    On Error Resume Next
      If TimeValue(Cells(R, 2).Value) > (TimeValue(Now()) + TimeValue("00:01:03")) Then
      '         Debug.Print Cells(R, 2).Value & "  >  " & TimeValue(Now()) + TimeValue("00:01:03")
      GoTo NextIteration
      End If
    While Not IsEmpty(Cells(R, C))
    If C = 2 Then
    CellValue = Format(Cells(R, C).Value, "HH:mm:ss")
    ElseIf C = 4 Then
    t = Cells(R, C).Value - (Vol(R, 1))
    Vol(R, 1) = Cells(R, C).Value
    CellValue = t
    '        Debug.Print Cells(R, 1).Value & t & " - " & Vol(R, 1)
    Else
    CellValue = Cells(R, C).Value '
    End If
    S = S & CellValue & ","     'Add contents of current cell to string 's' and a comma
    C = C + 1
    Wend
    a.writeline S 'write line to the file MyCSV.csv

    NextIteration:
Next R
   End Sub

0 个答案:

没有答案