Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
Hi all,
I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
On error resume next
set bk = workbooks("MyBook.xls") On error goto 0 if not bk is nothing then msgbox "MyBook.xls is already open in excel" else msgbox "MyBook.xls is not open" End if if you mean located on a shared drive and being used by someone else: http://support.microsoft.com?kbid=138621 XL: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=291295 XL2002: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=213383 XL2000: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=184982 WD97: VBA Function to Check If File or Document Is Open -- Regards, Tom Ogilvy "Aaron" wrote in message ... Hi all, I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
Hi Tom,
I cannot get this to work. It may be because I am using the Macro in workbook1 and need it to look at workbook2 and if open then run code. Would this make a difference? Thanks, Aaron "Tom Ogilvy" wrote: On error resume next set bk = workbooks("MyBook.xls") On error goto 0 if not bk is nothing then msgbox "MyBook.xls is already open in excel" else msgbox "MyBook.xls is not open" End if if you mean located on a shared drive and being used by someone else: http://support.microsoft.com?kbid=138621 XL: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=291295 XL2002: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=213383 XL2000: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=184982 WD97: VBA Function to Check If File or Document Is Open -- Regards, Tom Ogilvy "Aaron" wrote in message ... Hi all, I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
First, Tom offered two suggestions.
Which one did you try? And which one did you really mean to try? You may want to post the code that you tried, too. And one more question... If workbook1.xls is open in one instance of excel and workbook2.xls is open in another instance (not just different windows of the same instance), then you'll want to use Tom's second suggestion. Aaron wrote: Hi Tom, I cannot get this to work. It may be because I am using the Macro in workbook1 and need it to look at workbook2 and if open then run code. Would this make a difference? Thanks, Aaron "Tom Ogilvy" wrote: On error resume next set bk = workbooks("MyBook.xls") On error goto 0 if not bk is nothing then msgbox "MyBook.xls is already open in excel" else msgbox "MyBook.xls is not open" End if if you mean located on a shared drive and being used by someone else: http://support.microsoft.com?kbid=138621 XL: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=291295 XL2002: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=213383 XL2000: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=184982 WD97: VBA Function to Check If File or Document Is Open -- Regards, Tom Ogilvy "Aaron" wrote in message ... Hi all, I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
Hi Dave,
I used the first one because I only wanted to know if I had the file open in the same instance. The Error I am getting is when the file is not open and is "object required", debug is pointing to "if not bk is nothing then". Thanks, Aaron "Dave Peterson" wrote: First, Tom offered two suggestions. Which one did you try? And which one did you really mean to try? You may want to post the code that you tried, too. And one more question... If workbook1.xls is open in one instance of excel and workbook2.xls is open in another instance (not just different windows of the same instance), then you'll want to use Tom's second suggestion. Aaron wrote: Hi Tom, I cannot get this to work. It may be because I am using the Macro in workbook1 and need it to look at workbook2 and if open then run code. Would this make a difference? Thanks, Aaron "Tom Ogilvy" wrote: On error resume next set bk = workbooks("MyBook.xls") On error goto 0 if not bk is nothing then msgbox "MyBook.xls is already open in excel" else msgbox "MyBook.xls is not open" End if if you mean located on a shared drive and being used by someone else: http://support.microsoft.com?kbid=138621 XL: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=291295 XL2002: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=213383 XL2000: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=184982 WD97: VBA Function to Check If File or Document Is Open -- Regards, Tom Ogilvy "Aaron" wrote in message ... Hi all, I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
I added one line and it worked ok:
Dim bk As Workbook On Error Resume Next Set bk = Workbooks("MyBook.xls") On Error GoTo 0 If Not bk Is Nothing Then MsgBox "MyBook.xls is already open in excel" Else MsgBox "MyBook.xls is not open" End If Aaron wrote: Hi Dave, I used the first one because I only wanted to know if I had the file open in the same instance. The Error I am getting is when the file is not open and is "object required", debug is pointing to "if not bk is nothing then". Thanks, Aaron "Dave Peterson" wrote: First, Tom offered two suggestions. Which one did you try? And which one did you really mean to try? You may want to post the code that you tried, too. And one more question... If workbook1.xls is open in one instance of excel and workbook2.xls is open in another instance (not just different windows of the same instance), then you'll want to use Tom's second suggestion. Aaron wrote: Hi Tom, I cannot get this to work. It may be because I am using the Macro in workbook1 and need it to look at workbook2 and if open then run code. Would this make a difference? Thanks, Aaron "Tom Ogilvy" wrote: On error resume next set bk = workbooks("MyBook.xls") On error goto 0 if not bk is nothing then msgbox "MyBook.xls is already open in excel" else msgbox "MyBook.xls is not open" End if if you mean located on a shared drive and being used by someone else: http://support.microsoft.com?kbid=138621 XL: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=291295 XL2002: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=213383 XL2000: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=184982 WD97: VBA Function to Check If File or Document Is Open -- Regards, Tom Ogilvy "Aaron" wrote in message ... Hi all, I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron -- Dave Peterson -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test for Open File
Prefect! That Dave and Tom!!
"Dave Peterson" wrote: I added one line and it worked ok: Dim bk As Workbook On Error Resume Next Set bk = Workbooks("MyBook.xls") On Error GoTo 0 If Not bk Is Nothing Then MsgBox "MyBook.xls is already open in excel" Else MsgBox "MyBook.xls is not open" End If Aaron wrote: Hi Dave, I used the first one because I only wanted to know if I had the file open in the same instance. The Error I am getting is when the file is not open and is "object required", debug is pointing to "if not bk is nothing then". Thanks, Aaron "Dave Peterson" wrote: First, Tom offered two suggestions. Which one did you try? And which one did you really mean to try? You may want to post the code that you tried, too. And one more question... If workbook1.xls is open in one instance of excel and workbook2.xls is open in another instance (not just different windows of the same instance), then you'll want to use Tom's second suggestion. Aaron wrote: Hi Tom, I cannot get this to work. It may be because I am using the Macro in workbook1 and need it to look at workbook2 and if open then run code. Would this make a difference? Thanks, Aaron "Tom Ogilvy" wrote: On error resume next set bk = workbooks("MyBook.xls") On error goto 0 if not bk is nothing then msgbox "MyBook.xls is already open in excel" else msgbox "MyBook.xls is not open" End if if you mean located on a shared drive and being used by someone else: http://support.microsoft.com?kbid=138621 XL: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=291295 XL2002: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=213383 XL2000: Macro Code to Check Whether a File Is Already Open http://support.microsoft.com?kbid=184982 WD97: VBA Function to Check If File or Document Is Open -- Regards, Tom Ogilvy "Aaron" wrote in message ... Hi all, I need to create a If statment that tests if a Xls file is open or not. Any ideas? Thanks in advance. Aaron -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA Assistance needed to test for open file in a different direct | Excel Discussion (Misc queries) | |||
Test to see if a workbook is open | Excel Discussion (Misc queries) | |||
Test if a workbook is open already | Excel Programming | |||
Test that a workbook is open | Excel Programming | |||
test for workbook open | Excel Programming |