1. Tạo nút phóng to, thu nhỏ userform
- Tạo 1 modun
Option ExplicitPublic Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPublic Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPublic Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As LongPublic Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As LongPublic Const GWL_STYLE As Long = (-16) 'Sets a new window stylePublic Const WS_SYSMENU As Long = &H80000 'Windows stylePublic Const WS_MINIMIZEBOX As Long = &H20000Public Const WS_MAXIMIZEBOX As Long = &H10000Public Const SW_SHOWMAXIMIZED = 3Public lFormHandle As Long, lStyle As LongSub TombolMinMax(UserFormCaption As String)lFormHandle = FindWindow("ThunderDFrame", UserFormCaption)lStyle = GetWindowLong(lFormHandle, GWL_STYLE)lStyle = lStyle Or WS_SYSMENU 'SystemMenulStyle = lStyle Or WS_MINIMIZEBOX 'With MinimizeBoxlStyle = lStyle Or WS_MAXIMIZEBOX 'and MaximizeBoxSetWindowLong lFormHandle, GWL_STYLE, (lStyle)DrawMenuBar lFormHandleEnd Sub
- Sau đó chèn vào Private Sub UserForm_Initialize()
TombolMinMax (Me.Caption)
2. Tạo chế độ full màn hình cho userform: chèn vào Private Sub UserForm_Initialize()
* Tỷ lệ tùy bạn, hay thay 94 thành số phù hợp
With Application
.WindowState = xlMaximized
Zoom = Int(.Width / Me.Width * 94)
Zoom = Int(.Height / Me.Height * 94)
Width = .Width
Height = .Height
End With
3. Tự động sao lưu
'---auto backup---Sub Auto_Save()Dim saveDate As DateDim saveTime As VariantDim formatTime As StringDim formatDate As StringDim backupFolder As StringsaveDate = DatesaveTime = TimeformatTime = Format(saveTime, "hh.MM.ss")formatDate = Format(saveDate, "DD - MM - YYYY")Application.DisplayAlerts = FALSEbackupFolder = ThisWorkbook.Path & "\"ActiveWorkbook.SaveCopyAs Filename:=backupFolder & Replace(ActiveWorkbook.Name, ".xlsm", "") & " " & formatDate & " " & formatTime & ".xlsm"Application.DisplayAlerts = TRUECreateObject("WScript.Shell").Popup "Sao l" & ChrW(432) & "u th" & ChrW(224) & "nh c" & ChrW(244) & "ng! " & backupFolder, , "TH" & ChrW(212) & "NG TIN SAO L" & ChrW(431) & "U", 0 + 64'------end sao luu-----