ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro code to open a workbook only when closed (https://www.excelbanter.com/excel-programming/353543-macro-code-open-workbook-only-when-closed.html)

Jeff

Macro code to open a workbook only when closed
 
How can I check in a macro subroutine if the status of another file is open
or close. I would like to open another file only when it is not open.
Otherwise, Workbooks.Open Filename:="myfile.xls" simply returns an error
when the file is already open while the macro is running. Thanks a lot in
advance.

Kevin B

Macro code to open a workbook only when closed
 
You can use the following custom function to determine if the workbook is open.
================================================== ====
Function WBOpen(WorkBookName As String) As Boolean

On Error GoTo WorkBookNotOpen

If Len(Application.Workbooks(WorkBookName).Name) 0 Then
WBOpen = True
Exit Function
End If

WorkBookNotOpen:

End Function
================================================== ====
--
Kevin Backmann


"Jeff" wrote:

How can I check in a macro subroutine if the status of another file is open
or close. I would like to open another file only when it is not open.
Otherwise, Workbooks.Open Filename:="myfile.xls" simply returns an error
when the file is already open while the macro is running. Thanks a lot in
advance.



All times are GMT +1. The time now is 07:27 PM.

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