Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Code won't Run when getting Workbook name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paula - 28 Feb 2007 19:57 GMT
Imports Microsoft.Office.Interop.Excel

Public Class TransferTool

Private Sub btn_PrevData_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_PrevData.Click
       Dim wkbk As New Microsoft.Office.Interop.Excel.Workbook
       wkbk.Open(Me.txt_ImportFile.Text)

       strWrkBkNm = wkbk.Item(1).Name
       wkbk.Close()
       wkbk = Nothing

Gives an unspecified error, does anyone know why this will not run? Do I
need to install something?

Thanks,
Paula
Paula - 28 Feb 2007 20:14 GMT
Here is the error I receive:

Retrieving the COM class factory for component with CLSID
{00020819-0000-0000-C000-000000000046} failed due to the following error:
80040154.
Chip Pearson - 28 Feb 2007 20:31 GMT
Paula,

I think you need to change

Dim wkbk As New Microsoft.Office.Interop.Excel.Workbook
to
Dim wkbk As New Microsoft.Office.Interop.Excel.Workbooks

Note that this is plural "workbookS" not singular "workbook".

Just as a stylistic note, I would also change

Imports Microsoft.Office.Interop.Excel
to
Imports Excel = Microsoft.Office.Interop.Excel

Signature

Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

> Imports Microsoft.Office.Interop.Excel
>
[quoted text clipped - 14 lines]
> Thanks,
> Paula
Paula - 28 Feb 2007 21:02 GMT
Chip,

Thanks for your help.
If I add the s then I get an error telling me that the New keyword cannot be
used on an interface.

Then I take out the New and get this error at runtime:
Object reference not set to an instance of an object.

Any further advice?
Paula

> Paula,
>
[quoted text clipped - 30 lines]
> > Thanks,
> > Paula
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.