Help please!

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
 
A

Alan

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
 
A

Alan

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
 
J

Javed

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
 
A

Alan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top