处理Excel(或任何程序)的多个实例 [英] Dealing with Multiple Instances of Excel (or any program)

查看:90
本文介绍了处理Excel(或任何程序)的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理excel的多个实例,但我知道这将超出Excel。到目前为止,我有两种方法可以在另一个实例中激活工作簿,但我无法在激活的
实例之间传递或检索任何数据或命令。

I am trying to deal with multiple instances of excel at the moment, but I know this will be useful beyond Excel. So far I have 2 ways to activate the workbook in another instance, but I am unable to pass or retrieve any data or commands between the activated instance.

到目前为止,我有Appactivate(pid)或更全面的方法:

So far I have Appactivate(pid) or the more comprehensive method:

 

Sub A()

。 ......一堆代码....

....bunch of code....

RetVal = AttachThreadInput(tid1,tid2,True)

RetVal = SetForegroundWindow(hWnd2)

RetVal = ShowWindow(hWnd2,3)

RetVal = AttachThreadInput(tid1,tid2,False)

RetVal = AttachThreadInput(tid1, tid2, True)
RetVal = SetForegroundWindow(hWnd2)
RetVal = ShowWindow(hWnd2, 3)
RetVal = AttachThreadInput(tid1, tid2, False)

End Sub

 

SubB()

呼叫子(A)"其他工作簿"

工作簿( "其他工作簿"。范围("A1")。值="测试"

Call Sub(A) "Other workbook"
workbooks("Other workbook").Range("A1").Value = "test"

结束子

但这会返回下标范围

 

任何帮助将不胜感激,非常欢迎。

Any help would be appreciated and very welcome.

谢谢

推荐答案

如果您知道打开的文件的完整路径和名称其他工作簿

设置wb = GetObject(" c:\ [path] \ myFile.xls")

wb.Worksheets(" Sheet1")。范围("A1")。值=" test"

If you know the full path and name of the a file open in the other workbook
Set wb = GetObject("c:\[path]\myFile.xls")
wb.Worksheets("Sheet1").Range("A1").Value = "test"

并引用另一个实例

set xlApp2 = wb.Parent

set xlApp2 = wb.Parent

问候,

Peter Thornton

Regards,
Peter Thornton


这篇关于处理Excel(或任何程序)的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆