Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default VBA to check is someone else has a workbook open

I have a "Master Workbook" that (with VBA) moves worksheets out to other
workbooks located in subfolders in the same shared drive. My problem is that
I can't move a worksheet if another network user has that particular workbook
in the subfolder open (and nothing tells me that it didn't move.) How can I
check to see if someone (not me) has a workbook open and if so skip the move.
I found a UDF that someone posted that isn't working for me and I'm thinking
that's because I'm not the one who has the subfolder workbook open. Here is
the function that's not working:

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' This function checks to see if someone has a template file open
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function

and here is some of my Macro that tries to use that function:

SavePath = ActiveWorkbook.Path
....
....
template_place = "MBE SBR"
Sheets("MBE SBR").Select

If bIsBookOpen(SavePath & "\PROFILE (DFA and OS)\MBE SBR TEMPLATE.xls")
Then GoTo open_template

Workbooks.Open Filename:= _
SavePath & "\PROFILE (DFA and OS)\MBE SBR TEMPLATE.xls"
....
....
Sheets("MBE SBR").Move Befo=Workbooks("MBE SBR TEMPLATE.xls"). _
Sheets(1)
....
....
PROFILE_template:
....'the next move of another sheet
....
open_template:
MsgBox Prompt:="That template file is open so I can't distribute that
template."
nxt_template:
If template_place = "MBE SBR" Then GoTo PROFILE_template

Can anyone tell me what's wrong with my code or suggest alternative code to
use to do what I want to do?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default VBA to check is someone else has a workbook open


Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long

On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0

Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select

End Function

Sub test()
If Not IsFileOpen("C:\MyTest\volker2.xls") Then
Workbooks.Open "C:\MyTest\volker2.xls"
End If
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jim K." wrote in message
...
I have a "Master Workbook" that (with VBA) moves worksheets out to other
workbooks located in subfolders in the same shared drive. My problem is
that
I can't move a worksheet if another network user has that particular
workbook
in the subfolder open (and nothing tells me that it didn't move.) How can
I
check to see if someone (not me) has a workbook open and if so skip the
move.
I found a UDF that someone posted that isn't working for me and I'm
thinking
that's because I'm not the one who has the subfolder workbook open. Here
is
the function that's not working:

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' This function checks to see if someone has a template file open
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function

and here is some of my Macro that tries to use that function:

SavePath = ActiveWorkbook.Path
...
...
template_place = "MBE SBR"
Sheets("MBE SBR").Select

If bIsBookOpen(SavePath & "\PROFILE (DFA and OS)\MBE SBR TEMPLATE.xls")
Then GoTo open_template

Workbooks.Open Filename:= _
SavePath & "\PROFILE (DFA and OS)\MBE SBR TEMPLATE.xls"
...
...
Sheets("MBE SBR").Move Befo=Workbooks("MBE SBR TEMPLATE.xls"). _
Sheets(1)
...
...
PROFILE_template:
...'the next move of another sheet
...
open_template:
MsgBox Prompt:="That template file is open so I can't distribute that
template."
nxt_template:
If template_place = "MBE SBR" Then GoTo PROFILE_template

Can anyone tell me what's wrong with my code or suggest alternative code
to
use to do what I want to do?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default VBA to check is someone else has a workbook open

Thanks.

"Bob Phillips" wrote:


Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long

On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0

Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select

End Function

Sub test()
If Not IsFileOpen("C:\MyTest\volker2.xls") Then
Workbooks.Open "C:\MyTest\volker2.xls"
End If
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jim K." wrote in message
...
I have a "Master Workbook" that (with VBA) moves worksheets out to other
workbooks located in subfolders in the same shared drive. My problem is
that
I can't move a worksheet if another network user has that particular
workbook
in the subfolder open (and nothing tells me that it didn't move.) How can
I
check to see if someone (not me) has a workbook open and if so skip the
move.
I found a UDF that someone posted that isn't working for me and I'm
thinking
that's because I'm not the one who has the subfolder workbook open. Here
is
the function that's not working:

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' This function checks to see if someone has a template file open
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function

and here is some of my Macro that tries to use that function:

SavePath = ActiveWorkbook.Path
...
...
template_place = "MBE SBR"
Sheets("MBE SBR").Select

If bIsBookOpen(SavePath & "\PROFILE (DFA and OS)\MBE SBR TEMPLATE.xls")
Then GoTo open_template

Workbooks.Open Filename:= _
SavePath & "\PROFILE (DFA and OS)\MBE SBR TEMPLATE.xls"
...
...
Sheets("MBE SBR").Move Befo=Workbooks("MBE SBR TEMPLATE.xls"). _
Sheets(1)
...
...
PROFILE_template:
...'the next move of another sheet
...
open_template:
MsgBox Prompt:="That template file is open so I can't distribute that
template."
nxt_template:
If template_place = "MBE SBR" Then GoTo PROFILE_template

Can anyone tell me what's wrong with my code or suggest alternative code
to
use to do what I want to do?




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


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Then to check if a workbook is open Shawn Excel Discussion (Misc queries) 5 November 25th 06 04:29 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
Check if workbook open dkipping Excel Discussion (Misc queries) 4 May 24th 06 02:00 PM
Search open sheets in workbook and insert into open sheet punx77 Excel Discussion (Misc queries) 0 March 6th 06 05:07 PM
Excel workbook does not open in open window on desktop DeanH Excel Discussion (Misc queries) 2 March 8th 05 09:51 AM


All times are GMT +1. The time now is 02:13 PM.

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

About Us

"It's about Microsoft Excel"