View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default type mismatch, can't open a workbook?

From the looks of your existing code, it looked like you wanted a reference to
that newly opened workbook.

But you don't need to:

Public Sub openFile()
Const fName As String = "Book1.xls"
Const fPath As String = "MacOS X:SSP Folder:"
workbooks.open filename:=fPath & fName
end sub

But by using an object variable, it'll make it easier to do things later in the
code--but only if you need to!

Janis wrote:

I don't know why you can't just open a workbook why do you have to set it to
an object?
Is it because it is the open object? It is a little weird to think like that.

"Dave Peterson" wrote:

How about:

Public Sub openFile()
Const fName As String = "Book1.xls"
Const fPath As String = "MacOS X:SSP Folder:"
Dim wkb As Workbook
Set wkb = workbooks.open(filename:=fPath & fName)
end sub



Janis wrote:

i can't get this workbook to open. The folder, and filename is constant.
Thanks,

Public Sub openFile()
Const fName As String = "Book1.xls"
Const fPath As String = "MacOS X:SSP Folder:"
Dim wkb As Workbook
Set wkb = fPath & fName
wkb.Open

End Sub


--

Dave Peterson


--

Dave Peterson