Help please!

  • Thread starter Thread starter Bobby
  • Start date Start date
B

Bobby

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
 
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
 
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
 
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
 
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.
 
Back
Top