LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Yi Yi is offline
external usenet poster
 
Posts: 2
Default GetObject() returns different types of instances

Hi,

I am puzzled by my VB.NET application behavior. In the following code
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''
dim ExcelApp as Excel.Application
ExcelApp = GetObject(Nothing, "Excel.Application")
if (ExcelApp is nothing) then
ExcelApp = CreateObject("Excel.Application")
endi
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''
if there is an Excel process running before running this code, the variable
"ExcelApp" will refer to an instance of type "System.__ComObject". But if
Excel process is not present before running this code, this variable will
point to an instance of "Microsoft.Office.Interop.Excel.ApplicationCla ss".

If "ExcelApp" is pointing to "System.__ComObject", the code
"ExcelApp.Workbooks.Add()" will succeed. But if it is pointing to the other
type, this code will throw an exception which says "Object reference not set
to an instance of an object". Can anybody give some advices? Many thanks in
advance.

Regards,

--
Yi Chu
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I hide unused file types from file types list in save dial Estra Q Excel Discussion (Misc queries) 1 December 17th 09 12:36 PM
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
GetObject function R Avery Excel Programming 3 October 5th 04 07:20 PM
GetObject Michael Excel Programming 3 June 16th 04 01:28 PM
GetObject-question Tom Excel Programming 1 June 10th 04 05:17 PM


All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"