Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2006

Tip: Looking for answers? Try searching our database.

How to activate one of two sheets opened in Excel via C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Siv - 25 Jul 2006 22:39 GMT
Hi,
I am getting a problem, I have a Windows app in C# opening Excel and getting
2 workbooks open. During processing I want to switch between the two
workbooks to sometimes write to one sheet in workbook 1 and then at another
time to one sheet in workbook 2.

When I try to activate one or the other sheet using the following:

XLApp.Workbooks[2].Activate();

I get a compiler error saying:
"Ambiguity between method 'Excel._Workbook.Activate()' and non-method
'Excel.WorkbookEvents_Event.Activate'. Using method group."
No matter how I try different techniques to activate the sheet I get this
error, how can I make the compiler pick the 'Excel._Workbook.Activate()'
option and ignore the 'Excel.WorkbookEvents_Event.Activate' as it's driving
me mad now!

Signature

Siv
Martley, Near Worcester, United Kingdom.

pigeonrandle - 26 Jul 2006 03:01 GMT
Siv,

have you seen this?

http://blogs.officezealot.com/maarten/archive/2006/01/02/8918.aspx

found using

http://www.google.co.uk/search?hl=en&q=%22Ambiguity+between+method%22&meta=

("" can be very useful in hunting down error messages on the web (like
you didnt already know that :o)

it's might just be exactly what you want...

Hope that helps your sanity!
James Randle.

> Hi,
> I am getting a problem, I have a Windows app in C# opening Excel and getting
[quoted text clipped - 13 lines]
> option and ignore the 'Excel.WorkbookEvents_Event.Activate' as it's driving
> me mad now!
Siv - 26 Jul 2006 18:37 GMT
James,
Checked the link out and I'm still stumped. I tried changing my declaration
of the XLApp variable from:

private ApplicationClass XLApp;
to
private Excel.Application XLApp;
to
private Excel._Application XLApp;

I also tried selecting the code so that it worked off a workbook variable
and tried:

private _Workbook XLWB;
or
private Workbook XLWB;

Still gives the same error, if anyone can show me what I am doing wrong I
would be grateful, or show me a better way of activating the second sheet.
Perhaps I should always directly reference the second sheet when applying
any commands to it?
Signature

Siv
Martley, Near Worcester, United Kingdom.

> Siv,
>
[quoted text clipped - 34 lines]
>> driving
>> me mad now!
pigeonrandle - 27 Jul 2006 09:25 GMT
Siv,

private Excel.Application XLApp;

should be the way to go with the declaration.
You could try

XLApp.ActiveWorkBook.Worksheet("worksheetname").Activate

or

XLApp.Workbooks(0).Worksheet(1).Activate()

or a hybrid combination ... using the worksheet name instead of it's
index might help?

HTH,
James.

> James,
> Checked the link out and I'm still stumped. I tried changing my declaration
[quoted text clipped - 58 lines]
> >> driving
> >> me mad now!
Siv - 28 Jul 2006 17:42 GMT
James,
Thanks for your help, the C# compiler seems really pedantic at times, I
really can't see why it gets confused between and event and a method like
this?

I'll give this a go and see if my blues go away!

Signature

Siv
Martley, Near Worcester, United Kingdom.

> Siv,
>
[quoted text clipped - 81 lines]
>> >> driving
>> >> me mad now!
pigeonrandle - 30 Jul 2006 11:55 GMT
Siv,
I know what you mean. Perhaps 'C blunt' would have been a better name
for it.

James.

> James,
> Thanks for your help, the C# compiler seems really pedantic at times, I
[quoted text clipped - 95 lines]
> >> >> Siv
> >> >> Martley, Near Worcester, United Kingdom.
Cindy M  -WordMVP- - 27 Jul 2006 15:19 GMT
Hi Siv,

> When I try to activate one or the other sheet using the following:
>  
[quoted text clipped - 3 lines]
> "Ambiguity between method 'Excel._Workbook.Activate()' and non-method
> 'Excel.WorkbookEvents_Event.Activate'. Using method group."

See if the information on this page, section 2.4, helps

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_of2
003_bk/html/officeinteroperabilitych2_part2.asp

   -- Cindy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.