View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Subscript out of range setting Workbooks.Item(bookname)

You didn't share the FileNameOnly function.

Any chance you're stripping the extension in that function. If you are, then
don't do that. Depending on a windows setting (to show extensions for know file
types), you could have this trouble.

Another option would be to replace this:

moExcelApp.WorkBooks.Open FullPathName
Set moWorkBook = moExcelApp.WorkBooks.Item(fName)

with
set moworkbook = moExcelApp.WorkBooks.Open(FullPathName)



MP wrote:

Trying to write a class wrapper to handle calls to excel object model via
vb6.

'in cls
Private moExcelApp as Excel.Application
Private moWorkBook as Workbook

'FullPath = "Z:\0\0code\vb\excel\TestBook.xls"
Public Sub OpenWorkBook(FullPathName as String)
Dim fName as String

fName = FileNameOnly(FullPathName)
'fName = "TestBook"

If FileExists(FullPathName) Then
moExcelApp.WorkBooks.Open FullPathName

' subscript out of range error here
Set moWorkBook = moExcelApp.WorkBooks.Item(fName)

Else
LogError "File not found " & FullPathName
End If

I thought one could use a name as index to .Item property
what am I doing wrong?
Thanks
Mark


--

Dave Peterson