开发者

If a file is open get file to front [closed]

开发者 https://www.devze.com 2023-03-24 01:54 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_开发百科 Closed 11 years ago.

I get the following error when trying to open a workbook file.

The process cannot access the file '.. File.xls' because it is being used by another process.

Instead of opening the file again, if the file is already open, how do I bring that workbook forward.


Copied from OP's comment:

Excel App is on front. The thing is, I opened a WorkBook programmatically, came to front. Now I did some work on old workbooks, clicked the button again to open the Workbook which is already open. Now since its open, gave me exception. So instead of that I want that old sheet to come front.


This is a two step solution

  1. You have to first find the process that is currently using the file
  2. Then, once you have the ProcessId, you have to bring it to the front using the Win32 API


If you are using excel-interop, then all you need to do is set visible to true for your instance of the excel application. For example

excelApp.Visible = true;

even if if the value is already true, this will bring it to the front.

0

精彩评论

暂无评论...
验证码 换一张
取 消