changing visual studio 2005 code to c#

i have been working with visual studio 2005 express and would like to learn more about c#can someone assist in converting the code below its used from button 1 click on a windows form.

Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook

xlApp = CType(CreateObject("Excel.Application"), _
Microsoft.Office.Interop.Excel.Application)
xlBook = CType(xlApp.Workbooks.Open("C:\Program Files\Bernie\Co Books") _
, Microsoft.Office.Interop.Excel.Workbook)

xlApp.Application.Visible = True
Me.Close()



Answer this question

changing visual studio 2005 code to c#

  • Martin Svadbik

    Hi Dave thanks for the reply tried that link i cannot download as norton antivirus stops that site from downloading as its suspect so it keeps telling me
  • SteveLe

    Daniel i have tried just putting in say Co Books.xls then it operates with no error but just hangs with nothing happening at all.
  • SohaibM

    Thankyou for your reply Daniel i have put the reference for my excel document where the filename is ie "C:\\Documents & Settings\\Bernie\\My Docs\\etc" but i get the error message com exception unhandled cannot find C:etc.By the way i am using Visual C# Express Edition but it shouldnt make a difference as it doesnt in Visual Studio 2005 Express Edition with the code i originally gave you,any thoughts

    Regards Bernie


  • mgi1100

    Use System.Reflection.Missing.Value for the missing arguments.

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C# to C++ converter and VB to C++ converter
    Instant J#: VB to J# converter
    Clear VB: Cleans up VB.NET code
    Clear C#: Cleans up C# code



  • Raimund

    Microsoft.Office.Interop.Excel.Application xlApp;

    Microsoft.Office.Interop.Excel.Workbook xlBook;

    xlApp = (Microsoft.Office.Interop.Excel.Application) Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));

    xlBook = (Microsoft.Office.Interop.Excel.Workbook)xlApp.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);

    The whole list of Type.Missing is required because C# doesn't support optional parameters.



  • basin

    Daniel,have checked and its the same but wont open
  • Bob Sovers

    Double check the file name you want to open, there should be no difference in behavior between C# and VB.NET here...

  • changing visual studio 2005 code to c#