Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I did try from the web the following statement to see if the file is
open but it always try to open it! Can someone help? Thank's ahead pathsystemeinterne = "C:\Indic_Entr\interne\Système\Entrepot.xls" On Error Resume Next Set wBook = Workbooks(pathsystemeinterne) If wBook Is Nothing Then Workbooks.Open Filename:=pathsystemeinterne Set wBook = Nothing On Error GoTo 0 End If |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 11, 3:31*am, Bobby wrote:
I did try from the web the following statement to see if the file is open but it always try to open it! Can someone help? Thank's ahead pathsystemeinterne = "C:\Indic_Entr\interne\Système\Entrepot.xls" On Error Resume Next Set wBook = Workbooks(pathsystemeinterne) If wBook Is Nothing Then * Workbooks.Open Filename:=pathsystemeinterne * Set wBook = Nothing * On Error GoTo 0 End If Try comparing your file name with the files that are already open Sub test() Dim wbk As Workbook Dim nm As String For Each wbk In Workbooks nm = wbk.FullName Next End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 11, 3:31*am, Bobby wrote:
I did try from the web the following statement to see if the file is open but it always try to open it! Can someone help? Thank's ahead pathsystemeinterne = "C:\Indic_Entr\interne\Système\Entrepot.xls" On Error Resume Next Set wBook = Workbooks(pathsystemeinterne) If wBook Is Nothing Then * Workbooks.Open Filename:=pathsystemeinterne * Set wBook = Nothing * On Error GoTo 0 End If If you don't want to open it, try checking your workbook name against the names of the files that are already open Sub test() Dim wbk As Workbook For Each wbk In Workbooks if wbk.FullName = "C:\Indic_Entr\interne\Système\Entrepot.xls" then MsgBox "Workbook is already open" 'other code ... exit sub end if Next MsgBox "Workbook is not open" 'other code ... End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just another option.One advantage is that it does not need the loop
Sub CheckFile() Dim pathsystemeinterne As String, wBook As Workbook, fName As String pathsystemeinterne = "C:\Indic_Entr\interne\Système\Entrepot.xls" fName = StrReverse(Mid(StrReverse(pathsystemeinterne) _ , 1, InStr(1, StrReverse(pathsystemeinterne), "\") - 1)) On Error Resume Next Set wBook = Workbooks(fName) If wBook Is Nothing Then Workbooks.Open Filename:=pathsystemeinterne Set wBook = Nothing On Error GoTo 0 End If End Sub |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 11, 10:10*am, Javed wrote:
Just another option.One advantage is that it does not need the loop Sub CheckFile() * * Dim pathsystemeinterne As String, wBook As Workbook, fName As String * * pathsystemeinterne = "C:\Indic_Entr\interne\Système\Entrepot.xls" * * fName = StrReverse(Mid(StrReverse(pathsystemeinterne) _ * * , 1, InStr(1, StrReverse(pathsystemeinterne), "\") - 1)) * * On Error Resume Next * * Set wBook = Workbooks(fName) * * If wBook Is Nothing Then * * * Workbooks.Open Filename:=pathsystemeinterne * * * Set wBook = Nothing * * * On Error GoTo 0 * * End If End Sub But doesn't this still open the target file? A. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 11, 9:21*am, Alan wrote:
On Feb 11, 10:10*am, Javed wrote: Just another option.One advantage is that it does not need the loop Sub CheckFile() * * Dim pathsystemeinterne As String, wBook As Workbook, fName As String * * pathsystemeinterne = "C:\Indic_Entr\interne\Système\Entrepot.xls" * * fName = StrReverse(Mid(StrReverse(pathsystemeinterne) _ * * , 1, InStr(1, StrReverse(pathsystemeinterne), "\") - 1)) * * On Error Resume Next * * Set wBook = Workbooks(fName) * * If wBook Is Nothing Then * * * Workbooks.Open Filename:=pathsystemeinterne * * * Set wBook = Nothing * * * On Error GoTo 0 * * End If End Sub But doesn't this still open the target file? A.- Hide quoted text - - Show quoted text - It works! Thank you all. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|