PC Review


Reply
Thread Tools Rate Thread

Code won't Run when getting Workbook name

 
 
=?Utf-8?B?UGF1bGE=?=
Guest
Posts: n/a
 
      28th Feb 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF1bGE=?=
Guest
Posts: n/a
 
      28th Feb 2007
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.

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      28th Feb 2007
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

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


"Paula" <(E-Mail Removed)> wrote in message
news:95D8F42E-4661-4441-8505-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?UGF1bGE=?=
Guest
Posts: n/a
 
      28th Feb 2007
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
"Chip Pearson" wrote:

> 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
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email address is on the web site)
>
>
> "Paula" <(E-Mail Removed)> wrote in message
> news:95D8F42E-4661-4441-8505-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I call up a line of code that references a cell/range in theactive workbook workbook where I am running my macro from? Lav Microsoft Excel Programming 1 11th Nov 2008 05:04 PM
copy and paste using code from workbook to workbook =?Utf-8?B?YmlnZGFkZHkz?= Microsoft Excel Misc 2 14th Sep 2005 11:06 AM
run code on opening workbook and apply code to certain sheets =?Utf-8?B?SmFuZQ==?= Microsoft Excel Programming 7 8th Aug 2005 09:15 AM
Place code from current workbook to new workbook =?Utf-8?B?UWFzcGVj?= Microsoft Excel Programming 5 8th Jun 2005 04:12 AM
Reference code in another workbook from a calling workbook =?Utf-8?B?RGF0YXNvcnQ=?= Microsoft Excel Programming 1 4th Jan 2005 01:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 AM.