Bugs?? problem automate excel in VB.net .. please help~

I

Ivan

Hi All,

I have tried to automate excel in vb.net
and i found a problem that i can't find the solution in anywhere...
i hope someone can help me in this group....

the problem is i try using the excel function --
'Excel.Workbooks.Open("C:\Filename.xls")'
it pops up an error msg -- 'object reference not set to an instance of an
object'

Source code as folllow

Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
objExcel = CType(CreateObject("Excel.Application"),
Excel.Application)
Dim objOldCI As System.Globalization.CultureInfo =
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New
System.Globalization.CultureInfo("en-US")
fail==> objWorkBook = objExcel.Workbooks.Open(strFileName)
System.Threading.Thread.CurrentThread.CurrentCulture = objOldCI

Does anyone know the solution??.... please guide me into the right
direction...Thanks

cheers,
Ivan
 
J

Jorge

Hi

Maybe instead of using createobject
objExcel = New Excel.Application might work...

Kind Regards
Jorge
-----Original Message-----
Hi All,

I have tried to automate excel in vb.net
and i found a problem that i can't find the solution in anywhere...
i hope someone can help me in this group....

the problem is i try using the excel function --
'Excel.Workbooks.Open("C:\Filename.xls")'
it pops up an error msg -- 'object reference not set to an instance of an
object'

Source code as folllow

Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
objExcel = CType(CreateObject ("Excel.Application"),
Excel.Application)
Dim objOldCI As
System.Globalization.CultureInfo =
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New
System.Globalization.CultureInfo("en-US")
fail==> objWorkBook = objExcel.Workbooks.Open (strFileName)
System.Threading.Thread.CurrentThread.CurrentCulture =
objOldCI
 
J

Jorge

Got it before your try to open the file you need to
objWorkBook = objExcel.Workbooks

objExlSheet = objWorkBookOpen(strFileName)

Kind Regards
Jorge
 
I

Ivan

Sorry guys, I'm fool...
I forgot to emphasis the error only exist in Win98 machine

it works just fine in WinXP & Win2K

and one more thing Jorge...
I have tried your code before and it's not working in Win98 as well... (but
once again work fine in WinXP & Win2K)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top