Add items to the ROT( Running Objects Table)

。_饼干妹妹 提交于 2019-12-22 09:27:32

问题


I know how to use *****.GetActiveObject(ProgId), however the problem is that several of the Applications I use this code line on are not added to the ROT, even if they are already open, I get an HRESULT Error. However If I click on another Application and then return to the original Application, the code line works just fine.

The reason I am leaving this so vague, is because this is a problem I am having across 10+ applications.

The reason for me not posting code is because I do not believe this problem to be code based, rather I believe this problem to be due to a simple lack of understanding on my part.

One of the Most Important Programs I am having this issue with is "Microsoft Excel". All I want to do is be able to start the user at a specific cell.

I have looked all over for a decent explanation of how to use the *****.GetActiveObject(ProgId) in Excel, however, there does not seem to be any reasonable answers. The Program may be written in c#, however, if it is simpler in visual basic that is not a problem


回答1:


http://support.microsoft.com/kb/316126

COM servers are expected to register themselves in Running Object Table after startup. Office programs register themselves when they lose focus. If a program tries to attach to a running instance before the program loses focus, you may receive an error message. For additional information about how to work around this problem, click the article number below to view the article in the Microsoft Knowledge Base: 316125 PRB: Visual C# .NET Error Attaching to Running Instance of Office Application

Using code, you can change focus from the Office application to your own application (or to some other application) to allow it to register itself in the ROT. Additionally, if your code is starting the executable (.exe) file for the Office application, you may need to wait for the Office application to finish loading before you attempt to attach to the running instance.

Ensure another window is activated before attempting to connect. As shown in the example, you can use Form.Activate to focus your own form, thus causing the Office app to lose focus.



来源:https://stackoverflow.com/questions/27444419/add-items-to-the-rot-running-objects-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!