Notification texts go here Contact Us Buy Now!

Cara Menghilangkan Tombol Close Userform Excel

Cara Menghilangkan Tombol Close Userform Excel

 Setelah sebelumnya Saya mempublikasikan artikel mengenai Cara Membuat Userform Di Excel, pada kesempatan ini Saya akan berbagi (share) mengenai Cara Untuk Menghilangkan Tombol Close Userform Excel atau HIDDEN CLOSE BUTTON USERFORM. Seperti yang sudah kita ketahui bersama, bahwa pada saat kita membuat/menyisipkan Userform Di Excel pastinya terdapat sebuah tombol Close yang secara default muncul di pojok kanan atas dari Userform tersebut.

Cara Menghilangkan Tombol Close Userform Excel

Dan tombol Close tersebut tidak bisa kita hilangkan (sembunyikan) melalui properties dari Userform itu sendiri, kita harus melakukannya secara manual, dengan cara menyisipkan sebuah kode/script Macro melalui lembar kerja Visual Basic Excel itu sendiri. Dan berikut merupakan cara beserta kode/script Macro tersebut :


Cara Untuk Menghilangkan Tombol Close Userform Excel

1. Silahkan Copy kode/script Macro di bawah ini :

Option Explicit
Private Const GWL_STYLE = -16
Private Const WS_CAPTION = &HC00000
Private Const WS_SYSMENU = &H80000
Private Const SC_CLOSE = &HF060
#If VBA7 Then 'https://www.digimagz.net
    Private Declare PtrSafe Function GetWindowLong _
        Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, _
        ByVal nIndex As Long) As Long
    Private Declare PtrSafe Function SetWindowLong _
        Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, _
        ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare PtrSafe Function DrawMenuBar _
        Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare PtrSafe Function FindWindowA _
        Lib "user32" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    Private Declare PtrSafe Function DeleteMenu _
        Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, _
        ByVal wFlags As Long) As Long
    Private Declare PtrSafe Function GetSystemMenu _
        Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
        
#Else
    Private Declare Function GetWindowLong _
        Lib "user32" Alias "GetWindowLongA" ( _
        ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong _
        Lib "user32" Alias "SetWindowLongA" ( _
        ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function DrawMenuBar _
        Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function FindWindowA _
        Lib "user32" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    Private Declare Function DeleteMenu _
        Lib "user32" (ByVal hMenu As Long, _
        ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Public Declare Function GetSystemMenu _
        Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
        
#End If 'https://www.digimagz.net
Public Sub SystemButtonSettings(frm As Object, show As Boolean)
    Dim windowStyle As Long
    Dim windowHandle As Long
    windowHandle = FindWindowA(vbNullString, frm.Caption)
    windowStyle = GetWindowLong(windowHandle, GWL_STYLE)
    If show = False Then
        SetWindowLong windowHandle, GWL_STYLE, (windowStyle And Not WS_SYSMENU)
    Else
        SetWindowLong windowHandle, GWL_STYLE, (windowStyle + WS_SYSMENU)
    End If
    DrawMenuBar (windowHandle)
End Sub
Public Sub CloseButtonSettings(frm As Object, show As Boolean)
    Dim windowHandle As Long
    Dim menuHandle As Long
    windowHandle = FindWindowA(vbNullString, frm.Caption)
    If show = True Then
        menuHandle = GetSystemMenu(windowHandle, 1)
    Else
        menuHandle = GetSystemMenu(windowHandle, 0)
        DeleteMenu menuHandle, SC_CLOSE, 0&
    End If
End Sub

2. Silahkan tambahkan sebuah Module ke dalam lembar kerja Visual Basic kita, dan kemudian Paste kode/script Macro di atas ke dalam Module tersebut.

3. Jika sudah, silahkan Sobat Blogger tambahkan kode/script Macro di bawah ini ke dalam Userform yang ingin kita hilangkah (sembunyikan) tombol Close-nya, caranya klik kanan pada Userform tersebut kemudian pilih View Code

Private Sub UserForm_Initialize()
'https://www.digimagz.net
Call SystemButtonSettings(Me, False)
End Sub

4. Selesai.

Untuk menghilangkah (menyembunyikan) tombol Close pada Userform lain, silahkan tambahkan script/kode Macro pada kode nomor 3 (pada posisi Useform_Initialize). Demikian artikel mengenai Cara Menghilangkan Tombol Close Userform Excel, muda-mudahan apa yang sudah Saya sampaikan pada kesempatan ini bisa bermanfaat untuk kita semuanya. Sekian, terimakasih, dan selamat mencoba.

Posting Komentar

Silahkan tinggalkan komentar Anda di bawah ini dengan Sopan dan Santun :
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.