Having Finally passed the MSAD exams in C#, i thought that i should start looking to use these new skills in the code behind to programme excel 2003, so I start work on the examples given on the Visual Studio Tools for Office but they are for VB.Net and i come across a problem when trying to convert a section of code that uses the WITH, END WITH command e.g
VB.NET
With this.Application.CommandBars("Task Pane")
.Width =300
.Position = Microsoft.Office.Core.MsoBarPosition.msoBarLeft
END WITH
so i try to convert it to C# :
this.Application.CommandBars("Task Pane").Width = 300;
this.Application.CommandBars("Task Pane").Position = Microsoft.Office.Core.MsoBarPosition.msoBarLeft;
But it will not compile
ERROR:
'Microsoft.Office.Interop.Excel._Application.CommandBars' is a 'property' but is used like a 'method'
As anyone got any ideas.
I have also tried to get hold of the CommandBar object using this:
Office.
CommandBar z = this.Application.CommandBars("Task Pane");z.Width = 300;
z.Position = Microsoft.Office.Core.
MsoBarPosition.msoBarLeft;but I am still getting the same error.
Ron

VB.NET WITH command convert to C#
John Arlen
Please mark the best replies as answers.
bmcat
I 'm writing C# code but come from VB.NET background too. :)
Regarding your situation, may I suggest... try to use square bracket instead
C#'s Something["Name"] == VB's Something("Name")
HTH
Klaus Prückl
Segato
this.Application.CommandBars["Task Pane"].Width = 300;
this.Application.CommandBars["Task Pane"].Position = Microsoft.Office.Core.MsoBarPosition.msoBarLeft;
C# used square brackets ( [ & ] ) for a index property.