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.
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

JohnSz

New Member
Joined
Aug 10, 2010
Messages
4
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?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
I think you'll need to post your code that checks the password.
 

JohnSz

New Member
Joined
Aug 10, 2010
Messages
4

ADVERTISEMENT

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.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

JohnSz

New Member
Joined
Aug 10, 2010
Messages
4
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.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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).
 

Watch MrExcel Video

Forum statistics

Threads
1,122,658
Messages
5,597,403
Members
414,142
Latest member
Banyangt

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