Workbook already open Error

palmerk

Board Regular
Joined
Dec 6, 2005
Messages
121
I am creating a new workbook that would enable a user other than myself to open the workbook and a macro to receive info based on an automatic update. They will need to "reopen it" several times prior to being done for the day. I am using formulas to take out info particular accounts to provide a better information but they will not need to save it.

I am running into this error message

"Workbook.xls is already open. Reopening will cause any changes you made to be discarded. Do you want to reopen Workbook.xls?" with yes and no as options.

Is there a way that I can write VBA to say yes? :confused:
 
This is the simplest code I could come up with to do what it seems that you want:

Code:
Private Sub Workbook_Open()

For Each w In Workbooks
    If w.Name = "Book3.xls" Then
        GoTo GetOutNow:
    End If
Next w

Workbooks.Open ("Book3.xls")
GetOutNow:
End Sub

The code runs when "this workbook" is opened.
It loops through the list of open workbooks to see if "Book3.xls" is open.
If it finds that it is, then it goes to GetOutNow and does ... nothing; it skips the Workbooks.Open command.
If it completes the loop without finding "Book3.xls" then it opens that file.

You'd probably want error trapping in case Book3.xls doesn't exist, or reference to the path name, etc., but this seems to do the simple thing you want: Open the file if it's not already open; do nothing if it is.

Substitute your names to suit.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Sorry for delayed response, been away on summer leave. :biggrin: Your code looks OK to me (since it's the same as I use) but what do you mean by "The error came up on the code version" - where exactly is the error coming up and what error message are you getting?
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,129
Members
449,097
Latest member
mlckr

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