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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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
 
Upvote 0
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????
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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
Back
Top