Global Const App_Name As String = "Custom_App"
Global Const Sect2 As String = "Settings"
Global Const WM_SETICON = &H80
Global Close_Flag As Boolean
Public Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function ExtractIcon _
Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long
Public Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Public Declare Function SetForegroundWindow _
Lib "user32" _
(ByVal hwnd As Long) As Long
Sub SetExcelIcon()
Dim lngXLHwnd As Long, lngIcon As Long, strIconPath As String
'Change this to a valid icon path on your network/drive
strIconPath = "U:\proceng\wip\test_procs\wpoga\oga\Administration\PES Stuff\Data\SpaceStation.bmp"
lngXLHwnd = FindWindow("XLMAIN", Application.Caption)
lngIcon = ExtractIcon(0, strIconPath, 0)
SendMessage lngXLHwnd, WM_SETICON, False, lngIcon
End Sub
Sub Build_ToolBar()
Dim MyBar As CommandBar
On Error Resume Next
Application.CommandBars("MAIN_BAR").Delete
On Error GoTo 0
Set MyBar = Application.CommandBars.Add(Name:="MAIN_BAR", Position:=msoBarTop)
With MyBar
.Controls.Add Type:=msoControlButton, Before:=1
.Controls(1).Caption = "Unlock App"
.Controls(1).OnAction = "Admin_Access"
.Controls(1).FaceId = 260
.Controls.Add Type:=msoControlButton, Before:=1
.Controls(1).Caption = "Close Application"
.Controls(1).OnAction = "Closeup"
.Controls(1).FaceId = 263
.Visible = True
End With
End Sub
Sub Admin_Access()
Dim pwd As String
'better to use a textbox on a userform with the PasswordChar property set to *
pwd = InputBox("Password Please")
If pwd = "Password" Then
Call Hamstring_Off
Else
MsgBox "Sorry, that is the wrong password.", vbCritical, "Oops"
End If
SetForegroundWindow (Application.hwnd)
End Sub
Public Sub Closeup()
On Error Resume Next
Call Hamstring_Off
Application.CommandBars("MAIN_BAR").Delete
If ThisWorkbook.ReadOnly = False Then
ThisWorkbook.Save
End If
Close_Flag = True
Application.DisplayAlerts = False
Application.Quit
End Sub
Sub Hamstring_On()
Dim item As CommandBar
Dim Ad_Item
Dim Mb As VbMsgBoxResult
If Application.CommandBars(1).Enabled = False Then
Exit Sub
End If
Application.DisplayAlerts = False
For Each item In Application.CommandBars
If item.Name <> "MAIN_BAR" Then
item.Enabled = False
End If
Next item
SaveSetting App_Name, Sect2, "DisplayWorkbookTabs", CStr(ActiveWindow.DisplayWorkbookTabs)
ActiveWindow.DisplayWorkbookTabs = False
SaveSetting App_Name, Sect2, "DisplayFormulaBar", CStr(Application.DisplayFormulaBar)
Application.DisplayFormulaBar = False
SaveSetting App_Name, Sect2, "Task Pane", CStr(Application.CommandBars("Task Pane").Visible)
Application.CommandBars("Task Pane").Visible = False
SaveSetting App_Name, Sect2, "ShowWindowsInTaskbar", CStr(Application.ShowWindowsInTaskbar)
Application.ShowWindowsInTaskbar = False
SaveSetting App_Name, Sect2, "IgnoreRemoteRequests", CStr(Application.IgnoreRemoteRequests)
Application.IgnoreRemoteRequests = True
SaveSetting App_Name, Sect2, "AutoRecover", CStr(Application.AutoRecover.Enabled)
Application.AutoRecover.Enabled = False
On Error Resume Next
Application.VBE.MainWindow.Visible = False
On Error GoTo 0
'+ = Shift, ^ = Ctrl, % = Alt
Application.OnKey "{DELETE}", ""
Application.OnKey "+{DELETE}", ""
Application.OnKey "^{DELETE}", ""
Application.OnKey "{BACKSPACE}", ""
Application.OnKey "+{INSERT}", ""
Application.OnKey "^c", ""
Application.OnKey "^C", ""
Application.OnKey "^x", ""
Application.OnKey "^X", ""
Application.OnKey "^v", ""
Application.OnKey "^V", ""
Application.OnKey "^Q", ""
Application.OnKey "^q", ""
Application.OnKey "^W", ""
Application.OnKey "^w", ""
Application.OnKey "^N", ""
Application.OnKey "^n", ""
Application.OnKey "^O", ""
Application.OnKey "^o", ""
Application.OnKey "^P", ""
Application.OnKey "^p", ""
Application.OnKey "^F", ""
Application.OnKey "^f", ""
Application.OnKey "^G", ""
Application.OnKey "^g", ""
Application.OnKey "^H", ""
Application.OnKey "^h", ""
Application.OnKey "^A", ""
Application.OnKey "^a", ""
Application.OnKey "^K", ""
Application.OnKey "^k", ""
Application.OnKey "^L", ""
Application.OnKey "^l", ""
Application.OnKey "^S", ""
Application.OnKey "^s", ""
Application.OnKey "^{PGUP}", ""
Application.OnKey "^{PGDN}", ""
Application.OnKey "^{TAB}", ""
Application.OnKey "+^{TAB}", ""
Application.OnKey "{F1}", ""
Application.OnKey "^{F1}", ""
Application.OnKey "%{F1}", ""
Application.OnKey "+%{F1}", ""
Application.OnKey "{F2}", ""
Application.OnKey "{F3}", ""
Application.OnKey "+{F3}", ""
Application.OnKey "^{F3}", ""
Application.OnKey "+^{F3}", ""
Application.OnKey "{F4}", ""
Application.OnKey "+{F4}", ""
Application.OnKey "^{F4}", ""
Application.OnKey "%{F4}", ""
Application.OnKey "+^{F4}", ""
Application.OnKey "{F5}", ""
Application.OnKey "+{F5}", ""
Application.OnKey "^{F5}", ""
Application.OnKey "{F6}", ""
Application.OnKey "^{F6}", ""
Application.OnKey "+^{F6}", ""
Application.OnKey "{F7}", ""
Application.OnKey "%{F8}", ""
Application.OnKey "^{F9}", ""
Application.OnKey "^{F10}", ""
Application.OnKey "{F11}", ""
Application.OnKey "+{F11}", ""
Application.OnKey "^{F11}", ""
Application.OnKey "%{F11}", ""
Application.OnKey "{F12}", ""
Application.OnKey "+{F12}", ""
Application.OnKey "^{F12}", ""
Application.Caption = "Custom Application"
ActiveWindow.Caption = "Untitled"
Application.CommandBars.DisableAskAQuestionDropdown = True
Application.CommandBars.DisableCustomize = True
' bBuildCommandBars is contained in the Code Module provided in the
' CD that comes with PED First Edition by Bullen Bovey and Green
' It provides a table driven method to build a new command bar to replace the Excel Default
' Call bBuildCommandBars
' wksCommandBars is the worksheet that contains the Table that drives bBuildCommandBars
' Application.CommandBars(wksCommandBars.Range("A2").Value).RowIndex = 1
' Alternatively, build a new menu bar from scratch
Application.DisplayAlerts = True
Application.Calculation = xlCalculationManual
End Sub
Sub Hamstring_Off()
Dim item As CommandBar
On Error GoTo 0
For Each item In Application.CommandBars
item.Enabled = True
Next item
ActiveWindow.DisplayWorkbookTabs = CBool(GetSetting(App_Name, Sect2, "DisplayWorkbookTabs", True))
Application.DisplayFormulaBar = CBool(GetSetting(App_Name, Sect2, "DisplayFormulaBar", True))
Application.CommandBars("Task Pane").Visible = CBool(GetSetting(App_Name, Sect2, "Task Pane", False))
Application.ShowWindowsInTaskbar = CBool(GetSetting(App_Name, Sect2, "ShowWindowsInTaskbar", True))
Application.IgnoreRemoteRequests = CBool(GetSetting(App_Name, Sect2, "IgnoreRemoteRequests", False))
Application.AutoRecover.Enabled = CBool(GetSetting(App_Name, Sect2, "AutoRecover", True))
On Error Resume Next
DeleteSetting App_Name, Sect2
Application.OnKey "{DELETE}"
Application.OnKey "+{DELETE}"
Application.OnKey "^{DELETE}"
Application.OnKey "{BACKSPACE}"
Application.OnKey "+{INSERT}"
Application.OnKey "^c"
Application.OnKey "^C"
Application.OnKey "^x"
Application.OnKey "^X"
Application.OnKey "^v"
Application.OnKey "^V"
Application.OnKey "^Q"
Application.OnKey "^q"
Application.OnKey "^W"
Application.OnKey "^w"
Application.OnKey "^N"
Application.OnKey "^n"
Application.OnKey "^O"
Application.OnKey "^o"
Application.OnKey "^P"
Application.OnKey "^p"
Application.OnKey "^F"
Application.OnKey "^f"
Application.OnKey "^G"
Application.OnKey "^g"
Application.OnKey "^H"
Application.OnKey "^h"
Application.OnKey "^A"
Application.OnKey "^a"
Application.OnKey "^K"
Application.OnKey "^k"
Application.OnKey "^L"
Application.OnKey "^l"
Application.OnKey "^S"
Application.OnKey "^s"
Application.OnKey "^{PGUP}"
Application.OnKey "^{PGDN}"
Application.OnKey "^{TAB}"
Application.OnKey "+^{TAB}"
Application.OnKey "{F1}"
Application.OnKey "^{F1}"
Application.OnKey "%{F1}"
Application.OnKey "+%{F1}"
Application.OnKey "{F2}"
Application.OnKey "{F3}"
Application.OnKey "+{F3}"
Application.OnKey "^{F3}"
Application.OnKey "+^{F3}"
Application.OnKey "{F4}"
Application.OnKey "+{F4}"
Application.OnKey "^{F4}"
Application.OnKey "%{F4}"
Application.OnKey "+^{F4}"
Application.OnKey "{F5}"
Application.OnKey "+{F5}"
Application.OnKey "^{F5}"
Application.OnKey "{F6}"
Application.OnKey "^{F6}"
Application.OnKey "+^{F6}"
Application.OnKey "{F7}"
Application.OnKey "%{F8}"
Application.OnKey "^{F9}"
Application.OnKey "^{F10}"
Application.OnKey "{F11}"
Application.OnKey "+{F11}"
Application.OnKey "^{F11}"
Application.OnKey "%{F11}"
Application.OnKey "{F12}"
Application.OnKey "+{F12}"
Application.OnKey "^{F12}"
Application.Caption = ""
ActiveWindow.Caption = False
Application.CommandBars.DisableAskAQuestionDropdown = False
Application.CommandBars.DisableCustomize = False
Application.Calculation = xlCalculationAutomatic
End Sub