Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default 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.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"