View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Test if a workbook is open already

That works only with the workbook name, not the full file name,
as the OP needed.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Ron de Bruin" wrote in message
...
You need Chip's function also

Function IsWorkbookOpen(WBName As String) As Boolean
On Error Resume Next
IsWorkbookOpen = CBool(Len(Workbooks(WBName).Name))
End Function



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Chip Pearson" wrote in message
...
Try something like the following:

Dim WB As Workbook
Dim IsWorkbookOpen As Boolean
For Each WB In Workbooks
If WB.FullName = FName Then
IsWorkbookOpen = True
Exit For
End If
Next WB

If IsWorkbookOpen = False Then
Set WB = Workbooks.Open(FName)
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Kieran1028" wrote
in message ...

Follow-up on my last thread (which was answered, thus the new
thread,
but same project...)

At the beginning of my code, I use getopenfilename and then
open a
workbook. I want a check (if/then?) between the
getopenfilename and
the open command, that will check to see if the filename
entered is
already open, if it is, skip the open command and continue
with the
rest of the code. Make sense? This is what I have:

Sub get1degdata()
Dim fname As Variant
Dim Wkbk As Workbook
Dim wksht As Worksheet
fname = Application.GetOpenFilename("Excel
files(*.xls),*.xls")
Set Wkbk = Workbooks.Open(fname)
Wkbk.Activate
MsgBox fname