We help IT Professionals succeed at work.

how to check whether an Excel workbook is currently opened or not ?

Stanley Lai
Stanley Lai asked
on
Hi,

Would like to know how to check whether an Excel workbook is currently opened or not by using Excel VBA?  I'm now using Office 2013.  Thanks

Cheers
Stanley
Comment
Watch Question

Author

Commented:
A further addition ... after checked, if the Excel workbook is currently NOT opened, Open it then ... using Excel 2013 VBA
Social distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Change the name of the workbook.

Sub OpenWorkbook()
Dim wb As Workbook
Dim isOpen As Boolean


For Each wb In Workbooks
    If wb.Name = "MyWorkbook" Then
        isOpen = True
        Exit For
    End If
Next

If Not isOpen Then
    Workbooks.Open "C:\MyWorkbook.xls"
End If
End Sub

Open in new window

Fast response and up to the point directly. ^^  Thanks.
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
ou’re welcome and I’m glad I was able to help.

If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2019
              Experts Exchange Top Expert VBA 2018, 2019
              Experts Exchange Distinguished Expert in Excel 2018