Adding sound to password field

JohnSz

New Member
Joined
Aug 10, 2010
Messages
4
I am trying to add a sound file to the password prompt if the password is incorrect.

The password prompt appears when the file is being opened.

Can this be done?

Please assist.

Thank you.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
How do I make it work if the wrong password is entered? I've been able to have a workbook with a password and a worksheet with a command button to play the wave file, but am having problems with getting to work like I want it to.

Does that make sense?
 
Upvote 0
I have not written any code for the password checking. The password has been set by chosing File>Save As>Tools>General Options. BTW: I am using Excel 2007.
 
Upvote 0
I don't know any way of trapping that event. You would need to unprotect the file then use code like the following in the ThisWorkbook module

Code:
Private Declare Function PlaySound Lib "winmm.dll" _
  Alias "PlaySoundA" (ByVal lpszName As String, _
  ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000



Private Sub Workbook_Open()
If InputBox("Enter password") <> "pw" Then
    Call PlaySound("C:\Test\doh.wav", 0&, SND_ASYNC Or SND_FILENAME)
    Me.Close savechanges:=False
End If
End Sub
 
Upvote 0
Hmm....... I'll give this a try and see how it goes.

Would it be possible not to password protect the entire workbook, but instead have a user form to enter the password? Just a thought.
 
Upvote 0
I used an input box to capture the password. The disadvantage is that the typed password is visible. You could also use a userform with a textbox with the PasswordChar property set to * (or whatever).
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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