• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Systeemmenu ontzichtbaar houden

Status
Niet open voor verdere reacties.

Symphysodon

Gebruiker
Lid geworden
14 dec 2012
Berichten
468
Beste forummers,

Met een stuk code wat ik nu al een aantal jaar gebruik is het mogelijk het systeemmenu te verbergen en het kruisje te disablen. Dit werkt goed alleen op het moment ik dubbelklik o pde titelbalk komt het systeemmenu weer tevoorschijn waardoor de gebruiker de mogelijkheid heeft om het bestand op te slaan onder een andere naam.

Is het mogelijk om de functionaliteit van het dubbelklikken op de titelbalk om zo het systeemmenu zichtbaar te maken, te disabelen?

Uiteindelijk gaat het erom dat de SaveAs knop niet gebruikt kan worden. Daarvoor heb ik op het net een stukje code gevonden die dat voor elkaar krijgt alleen met die code werkt mijn Opslaan en Afsluiten knop ook niet meer.

Mvg
Marco
 
Plaats in ThisWorkbook:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then
    MsgBox "Het is niet mogelijk dit bestand onder een andere naam op te slaan.", vbCritical, "Opslaan Als... niet mogelijk"
    Cancel = True
End If
End Sub
 
Hallo symphysodon
Ik zie in een van je berichten dat je de systeem menu ( lint boven) kunt verbergen zoiets zocht ik namelijk ook
Ik wil de knop blad beveiligen laten verdwijnen en dat ik die zelf als beheerder weer kan aan roepen als dat nodig is zou u deze code kunnen plaatsen
 
Code:
Private Const MF_BYPOSITION As Long = &H400 ' Deletes the menus by position (this is our default).
Private Const MF_BYCOMMAND As Long = &H0        ' Deletes the menu by Command ID. This is rarely used and is shown here for information purposes only.
Private Const mlNUM_SYS_MENU_ITEMS As Long = 9  ' This is the number of items on the system menu

Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
    ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, _
    ByVal nPosition As Long, ByVal wFlags As Long) As Long
    
Public Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
 ByVal bScan As Byte, ByVal dwFlags As Long, _
 ByVal dwExtraInfo As Long)

#If Win64 Then
    Public Declare PtrSafe Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
#Else
    Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
#End If

Sub SetNumLockOn()
 
    If Not CBool(GetKeyState(VK_NUMLOCK)) Then
        keybd_event VK_NUMLOCK, 0, KEYEVENTF_EXTENDEDKEY, 0
        keybd_event VK_NUMLOCK, 0, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
    End If

End Sub

Sub landeninstellingen()
  Dim sDecimal As String
  Dim sTHousand As String
  Dim bUseSystem As Boolean
    
  sDecimal = Application.DecimalSeparator
  sTHousand = Application.ThousandsSeparator
  bUseSystem = Application.UseSystemSeparators

End Sub

Sub landeninstellingenterugzetten()
  Dim sDecimal As String
  Dim sTHousand As String
  Dim bUseSystem As Boolean
 
 Application.DecimalSeparator = sDecimal
 Application.ThousandsSeparator = sTHousand
 Application.UseSystemSeparators = bUseSystem
End Sub
Public Sub EnableActiveDialogMenuControls(DialogCaption As String)
    Dim lHandle As Long
    'On Error Resume Next
    DialogCaption = DialogCaption & vbNullChar
    lHandle = FindWindowA(vbNullString, DialogCaption)
    GetSystemMenu lHandle, True
End Sub
Public Sub DisableActiveDialogMenuControls(DialogCaption As String)
    Dim lHandle As Long, lCount As Long
    
    DialogCaption = DialogCaption & vbNullChar
    lHandle = FindWindowA(vbNullString, DialogCaption)
    ' Only continue if the passed window handle isn't zero.
    If lHandle <> 0 Then
        ' There are 9 items on the application control menu.
        ' Loop through and disable each one.
        For lCount = 1 To mlNUM_SYS_MENU_ITEMS
            ' The nPosition of the DeleteMenu function will always be 0,
            ' because as we delete each menu item, the next one moves up
            ' into the first position (index of 0).
            DeleteMenu GetSystemMenu(lHandle, False), 0, MF_BYPOSITION
        Next lCount
    End If
End Sub


Sub ExcelSluitenUitschakelen()
    DisableActiveDialogMenuControls (Application.Caption)
End Sub

Sub ExcelSluitenAanzetten()
    EnableActiveDialogMenuControls (Application.Caption)
End Sub

Public Sub RenameMSFormsFiles()
    Const tempFileName As String = "MSForms - Copy.exd"
    Const msFormsFileName As String = "MSForms.exd"
    On Error Resume Next
      
    'Try to rename the C:\Users\[user.name]\AppData\Local\Temp\Excel8.0\MSForms.exd file
    RenameFile Environ("TEMP") & "\Excel8.0\" & msFormsFileName, Environ("TEMP") & "\Excel8.0\" & tempFileName
    'Try to rename the C:\Users\[user.name]\AppData\Local\Temp\VBE\MSForms.exd file
    RenameFile Environ("TEMP") & "\VBE\" & msFormsFileName, Environ("TEMP") & "\VBE\" & tempFileName
End Sub

Private Sub RenameFile(fromFilePath As String, toFilePath As String)
    If CheckFileExist(fromFilePath) Then
        DeleteFile toFilePath
        Name fromFilePath As toFilePath
    End If
End Sub

Private Function CheckFileExist(path As String) As Boolean
    CheckFileExist = (Dir(path) <> "")
End Function

Private Sub DeleteFile(path As String)
    If CheckFileExist(path) Then
        SetAttr path, vbNormal
        Kill path
    End If
End Sub

Dit is de code die ik daar voor gebruikt hebt. Ergens op dit forum staat ook nog wel een voorbeeldbestand wat ik gepost heb.
 
De gegeven codes zet je in een module en om nu te voorkomen dat je heel Excel om zeep helpt gebruik je onderstaande code om alles weer origineel te maken. Die codes zet je dan in ThisWorkbook.
Code:
Private Sub Workbook_Open()
Dim s As Range
Dim Wb As Worksheet

'Numlock
SetNumLockOn

landeninstellingen

Application.DecimalSeparator = "."
Application.ThousandsSeparator = ","
Application.UseSystemSeparators = True

For Each Wb In Worksheets
    Wb.Protect Password:="pw", UserInterfaceOnly:=True
Next Wb

'Verbergen werkbalk
Application.DisplayFullScreen = True

For Each Wb In ActiveWorkbook.Worksheets
   Wb.Activate
   ActiveWindow.DisplayHeadings = False
Next

Application.DisplayFormulaBar = False

'Kruisje deactiveren
ExcelSluitenUitschakelen

'Disable CTRL + C etc.
Application.OnKey "^{c}", "" 'Copy
Application.OnKey "^{v}", "" 'Paste
Application.OnKey "^{x}", "" 'Cut
Application.CellDragAndDrop = False 'vulgreep

'Beveiligen kop- en voetteksten
headers

End Sub
Private Sub headers()

Application.ScreenUpdating = False
On Error Resume Next 'anders werkt de knop niet
With ThisWorkbook.ActiveSheet.PageSetup
   If .LeftHeader <> "" Then .LeftHeader = ""
   If .LeftFooter <> "Geldig met ingang van: " & Sheets("Toelichting").[n5] & ", versienummer: " & Sheets("Toelichting").[n6] Then .LeftFooter = "Geldig met ingang van: " & Sheets("Toelichting").[n5] & ", versienummer: " & Sheets("Toelichting").[n6]
   If .RightHeader <> "" Then .RightHeader = ""
   If .RightFooter <> "&A  &F" Then .RightFooter = "&A  &F"
   If .CenterFooter <> "" Then .CenterFooter = ""
   If .CenterHeader <> "" Then .CenterHeader = ""
End With

Application.ScreenUpdating = True
  
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    headers
    On Error Resume Next
    With ThisWorkbook.ActiveSheet
        If .Cells.Locked = True Then
            Cancel = False
        Else
            MsgBox ("You can not print this worksheet")
            Cancel = True
        End If
    End With
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If SaveAsUI = True Then
    MsgBox "Het is alleen toegestaan het bestand op te slaan met de desbetreffende knop in het werkblad.", vbCritical, "Opslaan Als... niet mogelijk"
    Cancel = True
End If

    headers
 
  'Terug zetten van het lint en de koppen
  Application.DisplayFullScreen = False
  ActiveWindow.DisplayHeadings = True
  Application.DisplayFormulaBar = True
  
  'Aanzetten kopieren plakken
  Application.OnKey "^{c}" 'Copy
  Application.OnKey "^{v}" 'Paste
  Application.OnKey "^{x}" 'Cut
  Application.CellDragAndDrop = True 'vulgreep
      
  landeninstellingenterugzetten

  'Activeren kruisje
  ExcelSluitenAanzetten

  'ActiveWorkbook.Close (False)

  Application.WindowState = xlMaximized
    
    
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    headers
 
    'Terug zetten van het lint en de koppen
    Application.DisplayFullScreen = False
    ActiveWindow.DisplayHeadings = True
    Application.DisplayFormulaBar = True
    
    'Aanzetten kopieren plakken
    Application.OnKey "^{c}" 'Copy
    Application.OnKey "^{v}" 'Paste
    Application.OnKey "^{x}" 'Cut
    Application.CellDragAndDrop = True 'vulgreep
        
    landeninstellingenterugzetten

    'Activeren kruisje
    ExcelSluitenAanzetten
  
    ActiveWorkbook.Close (False)
  
    Application.WindowState = xlMaximized
End Sub

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    headers
End Sub

Succes
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan