Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. opening MS Excel spreadsheet

opening MS Excel spreadsheet

Scheduled Pinned Locked Moved Visual Basic
helpcsharpcomannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lxhan
    wrote on last edited by
    #1

    I'm experiencing a problem w/ my application written in VB.Net. My application is suppose to open Excel, but when I try to create an object using CreateObject function it throws an exception, Specified cast is not valid. If I declare the xlApp as Excel.ApplicationClass it works, but a get the same problem, Specified cast is not valid, on the next line, xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook). I'm using Excel 2000 ver 9.02 and the OS is XP professional. I decided to load the latest version InteropServices, but I'm not using Office 2002. Even though it's loaded into the system the properties for the Excel COM object is pointing to the old version of Excel 2000. Any help would be appreciated. A sample of the code is as follows: Imports System.Runtime.InteropServices Imports Excel Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)

    T 1 Reply Last reply
    0
    • L lxhan

      I'm experiencing a problem w/ my application written in VB.Net. My application is suppose to open Excel, but when I try to create an object using CreateObject function it throws an exception, Specified cast is not valid. If I declare the xlApp as Excel.ApplicationClass it works, but a get the same problem, Specified cast is not valid, on the next line, xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook). I'm using Excel 2000 ver 9.02 and the OS is XP professional. I decided to load the latest version InteropServices, but I'm not using Office 2002. Even though it's loaded into the system the properties for the Excel COM object is pointing to the old version of Excel 2000. Any help would be appreciated. A sample of the code is as follows: Imports System.Runtime.InteropServices Imports Excel Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)

      T Offline
      T Offline
      tanstaafl28
      wrote on last edited by
      #2

      I'm assuming you also went into Projects-->Add References-->COM-->Microsoft Excel X.X Object Library (where X.X = your version of Excel). Also, I have had some odd problems with interops. Unless I used the full domain names, they wouldn't work. Dim xlApp As Microsoft.Office.Interop.Excel.Application Still coaxing software out of the can after all these years...

      A 1 Reply Last reply
      0
      • T tanstaafl28

        I'm assuming you also went into Projects-->Add References-->COM-->Microsoft Excel X.X Object Library (where X.X = your version of Excel). Also, I have had some odd problems with interops. Unless I used the full domain names, they wouldn't work. Dim xlApp As Microsoft.Office.Interop.Excel.Application Still coaxing software out of the can after all these years...

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Tanstaafl28, I figured out the problem. There was a conflicted with the PIA files. I just restalled Microsoft Office. Thanks for your time!!!! lxhan

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups