Is workbook open if not then open it

  • Thread starter Thread starter ianripping
  • Start date Start date
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
 
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
 
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
 
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
 
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
 

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

Back
Top