Excel problem

  • Thread starter Mircea Pleteriu
  • Start date
M

Mircea Pleteriu

Hi,

I am experiencing a problem with Excel which I cannot figure out.
Here it it.

I develop a C# plug in for Excel with VS for Office.
I want to copy a range from an external Excel document into the current
document at the position of the active cell.

Here is my code:
****************************
// Open the source workbook from where to copy the typical range

Excel.Application srcApp = new Excel.ApplicationClass();

Excel.Workbook srcWorkbook = srcApp.Workbooks.Open(fileName, Type.Missing,
Type.Missing, Type.Missing,

Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);


// Get range to copy

Excel.Name name = srcApp.Names.Item("MyRangeName", Type.Missing,
Type.Missing);

Excel.Range range = name.RefersToRange;

// Copy range to current document at the position of the active cell

range.Copy(ThisApplication.ActiveCell);

**************************

The problem is that the Copy method fails with the error message: "Copy
method of Range class failed."
 
M

Mircea Pleteriu

It works now.
The mistake was that I used 2 different application objects to open the
workbooks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top