将数据从 Hummingbird HostExplorer 复制到 Excel
Copying data from Hummingbird HostExplorer to Excel
我目前正在尝试创建一个脚本来将数据从 Hummingbird HostExplorer 屏幕复制到 Excel(本质上是屏幕抓取)。我可以毫无问题地创建 Excel 的实例,并且可以毫无问题地将数据粘贴到 Word 中,但我就是无法弄清楚(即使在网上搜索了几个小时之后)如何将数据实际粘贴到 Excel.
这是目前为止的代码:
Sub Main
Dim Host As Object
Dim HE as Object
Set HE = CreateObject( "HostExplorer" )
Set Host = HE.CurrentHost
Dim iPSUpdateTime
Dim HostExplorer as Object
Dim MyHost as Object
On Error goto ErrorCheck
Set HostExplorer = CreateObject("HostExplorer") ' Initialize HostExplorer Object
Set MyHost = HostExplorer.HostFromProfile("EDC") ' Set object for the desired session
iPSUpdateTime = 60 ' PS Update wait time set to 60 seconds
'-------------------------------------
' insertion of code to change to A226
'-------------------------------------
MyHost.RunCmd("Home")
MyHost.RunCmd("Back-Tab")
MyHost.Keys("a226")
MyHost.RunCmd("Enter")
MyHost.WaitPSUpdated iPSUpdateTime, TRUE
MyHost.Keys("001dis010101")
MyHost.RunCmd("Tab")
MyHost.RunCmd("Tab")
MyHost.RunCmd("Tab")
MyHost.RunCmd("Tab")
MyHost.Keys("c")
MyHost.RunCmd("Enter")
MyHost.WaitPSUpdated iPSUpdateTime, TRUE
'----------------------------
' code to copy data to Excel
'----------------------------
Dim XLS As Object
Set XLS = CreateObject("Excel.Sheet")
XLS.FileNewDefault
For i = 1 to Host.Rows
XLS.FONT "Courier New"
XLS.FontSize 8
Next i
'-------------
' Error check
'-------------
ErrorCheck:
if (Err = 440) Then
Msgbox "The specified session is not running.", 16, "Hummingbird Macro Error"
End If
Exit Sub
End Sub
当我 运行 这个时,它到达 XLS.FileNewDefault
但随后跳过 For i
部分并直接进入错误检查。但是,如果我更改:
Set XLS = CreateObject("Excel.Sheet")
到
Set XLS = CreateObject("Word.Basic")
它可以完美地粘贴到 Word 中。
我是不是漏掉了一些非常简单的东西?
以下代码创建一个 Excel 工作簿并将剪贴板的内容粘贴到新工作表中:
option explicit
dim XLS, Book, Sheet
'Load Excel Application.
Set XLS = CreateObject("Excel.Application")
'By default it is invisible, so make it visible.
XLS.visible = true
'Still there is no workbook, so add one now.
set Book=XLS.Workbooks.Add()
'By default a workbook has 3 worksheets; we will work on the first one.
set Sheet=Book.Sheets(1)
'Call sheet.paste to paste the content of the clipboard into the active cell
'(which is by default "A1").
Sheet.paste
我目前正在尝试创建一个脚本来将数据从 Hummingbird HostExplorer 屏幕复制到 Excel(本质上是屏幕抓取)。我可以毫无问题地创建 Excel 的实例,并且可以毫无问题地将数据粘贴到 Word 中,但我就是无法弄清楚(即使在网上搜索了几个小时之后)如何将数据实际粘贴到 Excel.
这是目前为止的代码:
Sub Main
Dim Host As Object
Dim HE as Object
Set HE = CreateObject( "HostExplorer" )
Set Host = HE.CurrentHost
Dim iPSUpdateTime
Dim HostExplorer as Object
Dim MyHost as Object
On Error goto ErrorCheck
Set HostExplorer = CreateObject("HostExplorer") ' Initialize HostExplorer Object
Set MyHost = HostExplorer.HostFromProfile("EDC") ' Set object for the desired session
iPSUpdateTime = 60 ' PS Update wait time set to 60 seconds
'-------------------------------------
' insertion of code to change to A226
'-------------------------------------
MyHost.RunCmd("Home")
MyHost.RunCmd("Back-Tab")
MyHost.Keys("a226")
MyHost.RunCmd("Enter")
MyHost.WaitPSUpdated iPSUpdateTime, TRUE
MyHost.Keys("001dis010101")
MyHost.RunCmd("Tab")
MyHost.RunCmd("Tab")
MyHost.RunCmd("Tab")
MyHost.RunCmd("Tab")
MyHost.Keys("c")
MyHost.RunCmd("Enter")
MyHost.WaitPSUpdated iPSUpdateTime, TRUE
'----------------------------
' code to copy data to Excel
'----------------------------
Dim XLS As Object
Set XLS = CreateObject("Excel.Sheet")
XLS.FileNewDefault
For i = 1 to Host.Rows
XLS.FONT "Courier New"
XLS.FontSize 8
Next i
'-------------
' Error check
'-------------
ErrorCheck:
if (Err = 440) Then
Msgbox "The specified session is not running.", 16, "Hummingbird Macro Error"
End If
Exit Sub
End Sub
当我 运行 这个时,它到达 XLS.FileNewDefault
但随后跳过 For i
部分并直接进入错误检查。但是,如果我更改:
Set XLS = CreateObject("Excel.Sheet")
到
Set XLS = CreateObject("Word.Basic")
它可以完美地粘贴到 Word 中。
我是不是漏掉了一些非常简单的东西?
以下代码创建一个 Excel 工作簿并将剪贴板的内容粘贴到新工作表中:
option explicit
dim XLS, Book, Sheet
'Load Excel Application.
Set XLS = CreateObject("Excel.Application")
'By default it is invisible, so make it visible.
XLS.visible = true
'Still there is no workbook, so add one now.
set Book=XLS.Workbooks.Add()
'By default a workbook has 3 worksheets; we will work on the first one.
set Sheet=Book.Sheets(1)
'Call sheet.paste to paste the content of the clipboard into the active cell
'(which is by default "A1").
Sheet.paste