-1

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.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Cannon
  • 2,725
  • 10
  • 45
  • 86

2 Answers2

3

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
Community
  • 1
  • 1
Pierre-Alain Vigeant
  • 22,635
  • 8
  • 65
  • 101
1

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.

Nick
  • 1,903
  • 2
  • 21
  • 40
  • 1
    Let me put the whole scenario: 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. – Cannon Jul 30 '11 at 04:22
  • @buffer so the app is on top, but you need to bring a worksheet to the front of the open application? – Nick Jul 30 '11 at 21:43
  • 1
    Yes. Thats what I am lokoing for. Excel is open. I want a particualr workbook to come on front. – Cannon Aug 04 '11 at 21:27