Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default check if file with generic name already open

I will be grateful for any advices re the following. I have read similar but
the file names are hard coded. I have a list of files to open using a macro
and to work on so file names are held in a variable as opposed to being hard
coded into the macro.

How do i check to see if a file is already open, the name is say held in
cell A10 on sheet 1 for example and the next to open will be say A11 and so
on.
--
with kind regards

Spike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default check if file with generic name already open


For i = 10 To Cells(Rows.Count).End(xlUp).Row
If IsFileOpen(Cells(i,"A").Value) Then
Msgbox Cells(i,"A").Value
End If
Next i


Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long

On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0

Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select

End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Spike" wrote in message
...
I will be grateful for any advices re the following. I have read similar

but
the file names are hard coded. I have a list of files to open using a

macro
and to work on so file names are held in a variable as opposed to being

hard
coded into the macro.

How do i check to see if a file is already open, the name is say held in
cell A10 on sheet 1 for example and the next to open will be say A11 and

so
on.
--
with kind regards

Spike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default check if file with generic name already open

sub test()
Dim wb As Workbook
Dim CheckFor As String

CheckFor = Range("A10").Value

For Each wb In Workbooks
If wb.Name = CheckFor Then MsgBox (CheckFor & " is open!")
Next wb
end sub


"Spike" wrote:

I will be grateful for any advices re the following. I have read similar but
the file names are hard coded. I have a list of files to open using a macro
and to work on so file names are held in a variable as opposed to being hard
coded into the macro.

How do i check to see if a file is already open, the name is say held in
cell A10 on sheet 1 for example and the next to open will be say A11 and so
on.
--
with kind regards

Spike

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for Open File! Ayo Excel Discussion (Misc queries) 2 August 11th 08 06:55 PM
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
Open Outlook with generic message jamphan Excel Discussion (Misc queries) 0 March 28th 06 03:59 PM
check if file already is open Mats Nilsson Excel Programming 2 September 12th 05 09:30 AM
how do I program for a 'generic' worksheet to open silverfox Excel Programming 1 November 12th 04 10:02 PM


All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"