Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Determining if a file is open using VBA

I working with several files, I write macros to open them, but I don't want
the macro to run if the file is already open, what command can I use to check
for this

Working in Excel
--
Helping Is always a good thing
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Determining if a file is open using VBA

Try this function
Copy it in a normal module

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function


You use it like this

If bIsBookOpen(sFileNameXls) Then......

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



"QuietMan" wrote in message ...
I working with several files, I write macros to open them, but I don't want
the macro to run if the file is already open, what command can I use to check
for this

Working in Excel
--
Helping Is always a good thing



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Determining if a file is open using VBA

Found This, but thanks for all the help

Sub Chk_IsFileOpen()
If Windows("Filenam.xls").Visible = True Then
Exit Sub
Else
Workbooks.Open Filename:= _
"P:\~ ~ ".xls"
End Sub
--
Helping Is always a good thing


"Ron de Bruin" wrote:

Try this function
Copy it in a normal module

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function


You use it like this

If bIsBookOpen(sFileNameXls) Then......

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



"QuietMan" wrote in message ...
I working with several files, I write macros to open them, but I don't want
the macro to run if the file is already open, what command can I use to check
for this

Working in Excel
--
Helping Is always a good thing




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Determining if a file is open using VBA

That works if the workbook isn't open? I would expect it to raise a
subscript out of range error.

--
Regards,
Tom Ogilvy

"QuietMan" wrote in message
...
Found This, but thanks for all the help

Sub Chk_IsFileOpen()
If Windows("Filenam.xls").Visible = True Then
Exit Sub
Else
Workbooks.Open Filename:= _
"P:\~ ~ ".xls"
End Sub
--
Helping Is always a good thing


"Ron de Bruin" wrote:

Try this function
Copy it in a normal module

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function


You use it like this

If bIsBookOpen(sFileNameXls) Then......

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



"QuietMan" wrote in message
...
I working with several files, I write macros to open them, but I don't
want
the macro to run if the file is already open, what command can I use to
check
for this

Working in Excel
--
Helping Is always a good thing






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
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
Determining Whether File Exists Magnivy Excel Programming 9 June 8th 06 04:51 AM
Open a file do a macro ( made) and open next succesive file SVTman74 Excel Programming 5 April 21st 06 10:14 PM
Determining File Size davidm Excel Programming 3 October 19th 05 07:34 AM
Determining if Other Workbooks Are Open Chaplain Doug Excel Programming 6 May 16th 05 08:12 PM


All times are GMT +1. The time now is 12:51 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"