Is workbook open if not then open it

I

ianripping

The path and filename of my workbook is in cell a1.

I want a macro that looks at this, see's if that workbook is alread
open in excel, if it is then it goes to next if not then it opens it.

Can anyone assist
 
F

Frank Kabel

Hi
try something like the following (assuming A1 stores the
path and B1 the filename):
sub foo()
dim fname
dim path
dim wbk as workbook
path=activesheet.range("A1").value
fname=activesheet.range("B1").value
on error resume next
set wbk = workbooks(fname)
on error goto 0
if wbk is nothing then
workbooks.open path&fname
set wbk = activeworkbook
end if
'...
end sub
 
I

ianripping

Looks good but errors on line

Workbooks.Open path&fname

should this be

Workbooks.Open FileName:=direc & WorkbookName = (path & fname)

even if i do this it errors and says cant open FALSE.xl
 
F

Frank Kabel

Hi
depends on what is in your cells. check for a missing '\'
you may add the line
msgbox path & fname
before this statement to check the names
 
I

ianripping

thanks got it not Sheets("macro").Select

Dim fname
Dim path
Dim wbk As Workbook
path = ActiveSheet.Range("Ae3").Value
fname = ActiveSheet.Range("ae5").Value
On Error Resume Next
Set wbk = Workbooks(fname)
On Error GoTo 0
If wbk Is Nothing Then
Workbooks.Open FileName:=path & fname
Set wbk = ActiveWorkbook
End I
 
Top