ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to skip files which are open? (https://www.excelbanter.com/excel-programming/356749-how-skip-files-open.html)

Jan Nademlejnsky

How to skip files which are open?
 
I run update macro loop to process about 50 spreadsheets, but sheets could
be used (open) by somebody. I need to skip processing of the sheet if it is
open. Something like this:

For R = 1 to 50
If FileR is open then goto Skip '<======This is what I need
Open_sheet
Update_it
Save_and_Close_it
Skip:
Next R

Thanks for your help

Jan



Jim Cone

How to skip files which are open?
 
Jan,
Something like the following...
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'----------------------
Sub OpenClosedFilesOnly()
Dim R
For R = 1 To 50
If Not IsItOpen(FileR) Then
Open_sheet
Update_it
Save_and_Close_it
End If
Skip:
Next R
End Sub

' Returns True or False.
'------------------
Function IsItOpen(ByRef BookName As String) As Boolean
Dim WB As Workbook
On Error Resume Next
Set WB = Workbooks(BookName)
IsItOpen = (Err.Number = 0)
Set WB = Nothing
End Function
'------------------------------------------------


"Jan Nademlejnsky" wrote in message
I run update macro loop to process about 50 spreadsheets, but sheets could
be used (open) by somebody. I need to skip processing of the sheet if it is
open. Something like this:

For R = 1 to 50
If FileR is open then goto Skip '<======This is what I need
Open_sheet
Update_it
Save_and_Close_it
Skip:
Next R

Thanks for your help
Jan




All times are GMT +1. The time now is 01:35 AM.

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