type mismatch, can't open a workbook?

G

Guest

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
 
D

Dave Peterson

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
 
G

Guest

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.
 
D

Dave Peterson

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top