ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help please! (https://www.excelbanter.com/excel-programming/444228-help-please.html)

Bobby[_4_]

Help please!
 
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

Alan

Help please!
 
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

Alan

Help please!
 
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

Javed

Help please!
 
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

Alan

Help please!
 
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.

Bobby[_4_]

Help please!
 
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.


All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com