Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
In Excel - Use Windows Explorer instead of File Open to open file | Excel Discussion (Misc queries) | |||
Determining Whether File Exists | Excel Programming | |||
Open a file do a macro ( made) and open next succesive file | Excel Programming | |||
Determining File Size | Excel Programming | |||
Determining if Other Workbooks Are Open | Excel Programming |