New install - problems with vb and excell

S

Stephen Plotnick

I just loaded a new machine and vb 2008 and office 2007 are the same on both
machines. The program was written on VB 2005 but I had to upgrade to 2008
with vista on my old machine.

I have a vb program that reads a text file and creates a spreadsheet. The
program compiles clean but on my statement.

oexcel = CreateObject("Excel.Application")



System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'System.__ComObject' to class
type 'Microsoft.Office.Interop.Excel.ApplicationClass'. COM components that
enter the CLR and do not support IProvideClassInfo or that do not have any
interop assembly registered will be wrapped in the __ComObject type.
Instances of this type cannot be cast to any other class; however they can
be cast to interfaces as long as the underlying COM component supports
QueryInterface calls for the IID of the interface."
Source="mpt2007"
StackTrace:
at mpt2007.Module1.Main() in C:\Users\xxxxxx\Documents\Visual Studio
2005\Projects\mpt2007\mpt2007\Module1.vb:line 46 at
System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state) at
System.Threading.ThreadHelper.ThreadStart()
InnerException:


My question is there something that is missing on my new machine that is
causing the issue??
 
S

Scott M.

I don't believe you are even creating the Excel reference correctly in the
first place. Try:

Dim xl As Application
xl = New Application

-Scott
 
F

Family Tree Mike

Scott said:
But if Option Strict is turned on in VS, then late binding wouldn't work.

Right, but they didn't say that option was on. Therefore it must be off.
 
S

Stephen Plotnick

I do see how to change strict option. I'm on the machine that works and the
option is set to off. When I set it to on I get tons of warnings. On my
other machine, unfortunately it is at home., there are not any errors.

I will check when I get home.
 
F

Family Tree Mike

Stephen said:
I do see how to change strict option. I'm on the machine that works and
the option is set to off. When I set it to on I get tons of warnings. On
my other machine, unfortunately it is at home., there are not any errors.

I will check when I get home.

That you got a ton of warnings is not surprising when you switch from
"Strict Off" to "Strict On". You cannot do late binding with it set
"On". I suspect your problem has more to do with the install of Office,
and nothing to do with that setting.
 
S

Scott M.

In Visual Studio, select the Tools menu, then Options.

Then select the "Projects and Solutions" category on the left and then the
"VB Defaults" sub-section.

Now, you will see a dropdown for Option Strict...

In general, it's a good idea to have it turned On, but that will require
that your code comply with this setting, which right now, I don't believe it
does. If it's on, leave it on. If it's off, turn it on.

Now, turning that setting on for Visual Studio only affects new projects
that you create from that point forward and it can still be set on a project
by project basis, so you'll still have to see if the project in question is
overriding that setting.

Do that by opening your project and double clicking the "My Project" node of
your project in the Solution Explorer window.
Then select the "Compile" tab in the dialog. You will see a drop down that
indicates if Option Strict is on or off. If it's off, then turn it on.

Change your code to what I suggested earlier:

Dim xl As Application
xl = New Application

instead of:

oexcel = CreateObject("Excel.Application")


-Scott
 
S

Stephen Plotnick

That did work, I got past that error and now another issue has arisen.

I also read an access db to get some information that is needed to populate
the excel report. I'm getting this weird message.

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local
machine.

Why am I getting this message. My office 2007 is properly registered
andapparently I now have two errors that are present that were not on my
other machine.

Thanks for any assistance,
Steve
Scott M. said:
In Visual Studio, select the Tools menu, then Options.

Then select the "Projects and Solutions" category on the left and then the
"VB Defaults" sub-section.

Now, you will see a dropdown for Option Strict...

In general, it's a good idea to have it turned On, but that will require
that your code comply with this setting, which right now, I don't believe
it does. If it's on, leave it on. If it's off, turn it on.

Now, turning that setting on for Visual Studio only affects new projects
that you create from that point forward and it can still be set on a
project by project basis, so you'll still have to see if the project in
question is overriding that setting.

Do that by opening your project and double clicking the "My Project" node
of your project in the Solution Explorer window.
Then select the "Compile" tab in the dialog. You will see a drop down that
indicates if Option Strict is on or off. If it's off, then turn it on.

Change your code to what I suggested earlier:

Dim xl As Application
xl = New Application

instead of:

oexcel = CreateObject("Excel.Application")


-Scott
 
S

Stephen Plotnick

I figured out this problem. It had to do with running in 32 instead of 64
for the oledb.4.0.

All is working.... thanks
 

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