View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Lenny_821[_9_] Lenny_821[_9_] is offline
external usenet poster
 
Posts: 1
Default Test if a workbook is open already


This is what I use;

Dim wbk As Workbook
Dim old_book As Workbook
Set old_book = ActiveWorkbook
On Error Resume Next
Set wbk = Workbooks("Test.xls")
On Error GoTo 0
If wbk Is Nothing Then
Workbooks.Open Filename:= _
"C:\Documents\test.xls"
old_book.Activate
Exit Sub
End If

Lenny

Kieran1028 Wrote:
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
workbook. I want a check (if/then?) between the getopenfilename an
the open command, that will check to see if the filename entered i
already open, if it is, skip the open command and continue with th
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
.
.
.
Thanks,
Kiera


--
Lenny_82
-----------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...fo&userid=1517
View this thread: http://www.excelforum.com/showthread.php?threadid=31944