Alt F11 Popup Msg

torweb

Board Regular
Joined
Dec 1, 2003
Messages
136
I've locked everything in my workbook project so it now operates as a stand-alone application after openning, then returns all Excel funtions to "normal" on closing. For the last bit of 'frosting' I'd like to post a popup msg if (when) a user types Alt F11, that warns against accessing any macros out of the worksheets.

Is this a do-able feature. Even better, can the Alt F11 function be password protected?

Thanks in advance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Well

there's a way to lock your vba project, so even if the user goes in the vb editor, he won't be able of seeing your code. That's a better way to protect it. Because, if you disable the Alt+F11 combinaison on loading, well, if the user doesn't enable the macro, he will still be able to use the Alt+f11 combinaison.


Anyway, here's a way to disable when workbook opened

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "%{F11}", ""
End Sub

To enable it again before closing:

Private Sub Workbook_Open()
Application.OnKey "%{F11}"
End Sub


You can also add a sub like:

Sub DisableAltF11()
MsgBox "These keys are disabled"
End Sub

And use:
Application.OnKey "%{F11}", "DisableAltF11"
instead of
Application.OnKey "%{F11}", ""

Hope This Helps,
 
Upvote 0
there's a way to lock your vba project, so even if the user goes in the vb editor, he won't be able of seeing your code. That's a better way to protect it. Because, if you disable the Alt+F11 combinaison on loading, well, if the user doesn't enable the macro, he will still be able to use the Alt+f11 combinaison.

Not to mention the fact that if the user has another workbook open and a reason to be in the VB Editor, they won't be able to get in that way, which will really... um... irritate :-D them.
 
Upvote 0
hi!
does disabling the AltF11 combination also prohibet the
user from accessing the VBE by rigth clicking the sheet name and choosing view code?
 
Upvote 0
Stepping back, what I would like to do is just warn the user that if they should hit Alt F11, then go to the Tools menu and activate any of the listed Macros, they may accidentaly delete or alter data in the Workbook. If they then still feel driven to click on a Macro...they've at least been warned.

They'll always find a way, I'm just trying to cover myself so I can say "I told you so."

So...the question can be, is it possible to display a popup that's activiated by someone hitting the Alt F11 key sequence?

I'll drop it after this round...

Thanks as always!
 
Upvote 0
Add the code below in ThisWorkbook module

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Application.OnKey "%{F11}", "AltF11Pressed"
End Sub

Sub AltF11Pressed()

If MsgBox("Are you sure you wanna go in the VB editor?", vbYesNo, "Confirmation") = vbYes Then
        Application.OnKey "%{F11}"
        Application.SendKeys "%{F11}"
End If

End Sub

Is it doing what you want?
 
Upvote 0
Mat,

Pasted your code into a workbook module but Alt F11 still opens the VB Editor Window. If I run the Sub AltF11pressed(), and answer "Yes", it zips past the VB Editor Window then stays on the open worksheet.

Seems like it's miss something small...

Thanks
 
Upvote 0
Hooray!

I think this did it...

The following code goes into ThisWorkbook;

Private Sub Workbook_Open()
Application.OnKey "%{F11}", "DisableAltF11"
Application.OnKey "%{F8}", "DisableAltF8"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "%{F11}", ""
Application.OnKey "%{F8}", ""
End Sub

Next paste the following code into a Module;

Sub DisableAltF11()

Dim strResp As String

strResp = InputBox("Enter Password to Access Alt F11", "Password")

If strResp = "pass123" Then
Application.ScreenUpdating = True
Application.OnKey "%{F11}"
Application.SendKeys "%{F11}"
Else
MsgBox "Invalid Password - Alt F11 Is Disabled"
End If

End Sub

Sub DisableAltF8()

Dim strResp As String

strResp = InputBox("Enter Password to Access Alt F8", "Password")

If strResp = "pass123" Then
Application.ScreenUpdating = True
Application.OnKey "%{F8}"
Application.SendKeys "%{F8}"
Else
MsgBox "Invalid Password - Alt F8 Is Disabled"
End If

End Sub

If the user hits Alt F11 or Alt F8, they're asked for a password. The correct password will give them the VBA Editor or the Macro Listing. The incorrect passworkd will just prompt them and return to the worksheet.

That's what I needed. The answer was a little of everyone's input!

Thanks to all.....

WHAT A WEBSITE!!!!!!!!!!!!!!!!!!!!!!!!!
 
Upvote 0
If you simply lock the project, the user can still get into the VBE but won;t be able to change or delete any macros.

I don;t really see the point of adding a warning message. Just keep the user out of your code and your safe.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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