Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Code won't Run when getting Workbook name

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Code won't Run when getting Workbook name

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Code won't Run when getting Workbook name

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" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Code won't Run when getting Workbook name

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" wrote in message
...
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
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
copy and paste using code from workbook to workbook bigdaddy3 Excel Discussion (Misc queries) 2 September 14th 05 11:06 AM
run code on opening workbook and apply code to certain sheets Jane Excel Programming 7 August 8th 05 09:15 AM
Code in one workbook to call code in another XL file [email protected] Excel Programming 2 August 1st 05 03:37 PM
Place code from current workbook to new workbook Qaspec Excel Programming 5 June 8th 05 04:12 AM
Reference code in another workbook from a calling workbook Datasort Excel Programming 1 January 4th 05 01:13 AM


All times are GMT +1. The time now is 08:14 AM.

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

About Us

"It's about Microsoft Excel"