View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
PBcorn PBcorn is offline
external usenet poster
 
Posts: 79
Default error 9 - simple code

....which seems to be due to the "if wb.fullname = path" line.

"PBcorn" wrote:

This generates a type mismatch error 13. please advise.

"Sam Wilson" wrote:

It's because the workbooks collection contains only open workbooks.

You can try the following, which checks all the open workbooks against the
path you've specified:

Sub test()

Dim path As String
path = "C:\blah.xls"

Dim wb As Workbook
For Each wb In Workbooks
If wb.FullName = path Then Exit Sub
Next wb

Workbooks.Open Filename:=path

End Sub


You should be able to

"PBcorn" wrote:

to open a workbook if it is not already open:

dim path as string

path = " letter:\...\\workbook.xls"

If Workbooks(path).IsOpen = False Then
workbooks.open filename:=path

Gives subscript out of range. The solutions i found by searching the forum
are a bit long-winded - why doesn't the above work?