VBA and password prompts

excelheaven

New Member
Joined
Sep 21, 2008
Messages
3
I have a read only workbook that multiple users use to send data via code to a master database. The master is password protected and the code enters the password upon opening. Each time the master is open for a split second, but very occasionally, two users may try and access it at the same time.

When this happens, the password prompt for the master sheet appears. I have written an error handling routine to respond to the "cannot open workbook error" to tell the user to try again and which then safely exits the routine, but I want to know how to code in to cancel the password prompt when it appears.

Anyone got any ideas?

Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
To open the file I just use:

Workbooks.Open Filename:= _
"Z:\Spread\Master Database.xlsb", Password:="something"

If the workbook is already open on another machine then the password prompt appears.

Thanks
 
Upvote 0
Post your existing code referred to below, please.

I have written an error handling routine to respond to the "cannot open workbook error"
 
Upvote 0
This is the Error HAndler - but it only kicks in after the user has responded to the password prompt to abort the routine and inform the user. An error is not generated when the password prompt first appears.

EH:
If Err = 1004 Then
MsgBox "There is a problem processing your" + vbCrLf + "request at this time." + vbCrLf + "Please try again", vbOKOnly + vbCritical, "Cannot proceed"
Sheets("Home").Select
End
End If

Thanks
 
Upvote 0
Try modifying your WB Open code to

On Error GoTo EH
Workbooks.Open Filename:= _
"Z:\Spread\Master Database.xlsb", Password:="something"
EH:
MsgBox "There is a problem processing your" + vbCrLf + "request at this time." + vbCrLf + "Please try again", vbOKOnly + vbCritical, "Cannot proceed"
Sheets("Home")

Maybe?
Not sure - unable to test here...
 
Upvote 0
Correction...

On Error GoTo EH
Workbooks.Open Filename:= _
"Z:\Spread\Master Database.xlsb", Password:="something"
Exit Sub 'originally omitted
EH:
MsgBox "There is a problem processing your" + vbCrLf + "request at this time." + vbCrLf + "Please try again", vbOKOnly + vbCritical, "Cannot proceed"
Sheets("Home").Select
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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