Determining if Workbook is open

youngda

Board Regular
Joined
Jun 13, 2006
Messages
81
I need a line of code that will tell me, yes or no, if a workbook is already opened by the computer. Anybody know?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
From www.OzGrid.com:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> IsWorkBookOpen()
<SPAN style="color:#007F00">''''''''''''''''''''''''''''''''''''''''''</SPAN>
<SPAN style="color:#007F00">'Written by www.ozgrid.com</SPAN>

<SPAN style="color:#007F00">'Test to see if a Workbook is open.</SPAN>
<SPAN style="color:#007F00">''''''''''''''''''''''''''''''''''''''''''</SPAN>

<SPAN style="color:#00007F">Dim</SPAN> wBook <SPAN style="color:#00007F">As</SPAN> Workbook

    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> wBook = Workbooks("Personal.xls")

        <SPAN style="color:#00007F">If</SPAN> wBook <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'Not open</SPAN>
            MsgBox "Workbook is not open", _
            vbCritical, "OzGrid.com"
            <SPAN style="color:#00007F">Set</SPAN> wBook = <SPAN style="color:#00007F">Nothing</SPAN>
            <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0
        <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'It is open</SPAN>
            MsgBox "Yes it is open", _
            vbInformation, "OzGrid.com"
            <SPAN style="color:#00007F">Set</SPAN> wBook = <SPAN style="color:#00007F">Nothing</SPAN>
            <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,

Smitty
 

youngda

Board Regular
Joined
Jun 13, 2006
Messages
81
The whole function

Well, your guy's advice has been useful, but I still get flustered when I try to adapt all of it to my situation. The following is the function I am trying to create written out in English. Maybe you can help me translate this into working code

OutputBook = "C:\Documents and Settings\All Users\Desktop\" & Format(Date, "yymmdd") & " Schwab Trades.csv"

'If OutputBook does not exist Then
'Workbooks.Add
'Else If OutputBook exists but is not Open
'Workbooks.open(OutputBook)
'Else If OutputBook exists and is open
'Workbooks(OutputBook).activate <-- This last statement hasa not been working when its isolated and alone????
 

Forum statistics

Threads
1,136,995
Messages
5,679,037
Members
419,801
Latest member
spinjector

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top