Microsoft Excel是Microsoft為使用Windows和Apple Macintosh操作系統的電腦編寫的一款電子表格軟件。直觀的界面、出色的計算功能和圖表工具,再加上成功的市場營銷,使Excel成為最流行的個人計算機數據處理軟件。 我們已經有了一系列怎樣增強 VBA 窗體的文章,VBA 的窗體和一般正常的窗體區別很大,比如就不可以通過用鼠標拖動窗體的邊框,我們今天就講講怎樣給 VBA 窗體添加這個功能。  ?操作如下: ?在Excel 的VBE窗口中插入一個用戶窗體,將其命名為 frmNotEnabledCloseIcon。然后再添加一個模塊。在窗體和模塊中添加后面所列代碼。 ?在工作薄中的工作表中添加一窗體按鈕控件,指定其設置宏 ShowNotEnabledCloseIconForm, 其供示范之用. ? 具體代碼: ? "frmThickFram" 窗體代碼 '******************************** '---此模塊演示怎樣刪除窗體標題欄--- www.office26.com '******************************** '以下聲明API函數 #If Win64 Then '64位 '取得窗體樣式位 Private Declare PtrSafe Function GetWindowLong _ Lib "user32" _ Alias "GetWindowLongPtrA" ( _ ByVal Hwnd As LongPtr, _ ByVal nIndex As Long) _ As LongPtr '查找窗口 Private Declare PtrSafe Function FindWindow _ Lib "user32" _ Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) _ As LongPtr '設置窗體樣式位 Private Declare PtrSafe Function SetWindowLong _ Lib "user32" _ Alias "SetWindowLongPtrA" ( _ ByVal Hwnd As LongPtr, _ ByVal nIndex As Long, _ ByVal dwNewLong As LongPtr) _ As LongPtr '繪制窗體標題欄 Private Declare PtrSafe Function DrawMenuBar _ Lib "user32" ( _ ByVal Hwnd As LongPtr) _ As Long #Else '取得窗體樣式位 Private Declare Function GetWindowLong _ Lib "user32" _ Alias "GetWindowLongA" ( _ ByVal hwnd As Long, _ ByVal nIndex As Long) _ As Long '查找窗口 Private Declare Function FindWindow _ Lib "user32" _ Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) _ 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 #End If #If Win64 Then '64位 Private hWndForm As LongPtr Private FIstype As LongPtr #Else Private hWndForm As Long Private FIstype As Long #End If '以下定義常數和變量 Private Const GWL_STYLE = (-16) '窗口樣式 Private Const WS_THICKFRAME = &H40000 '可更改大小 '---關閉按鈕--- Private Sub btnClose_Click() Unload Me End Sub '---窗體初始化--- Private Sub UserForm_Initialize() On Error Resume Next '查找窗體句柄 hWndForm = FindWindow("ThunderDFrame", Me.Caption) '取得窗體樣式 FIstype = GetWindowLong(hWndForm, GWL_STYLE) '窗體樣式:原樣式和可拖動邊框改變大小 FIstype = FIstype Or WS_THICKFRAME '重設窗體樣式 SetWindowLong hWndForm, GWL_STYLE, FIstype '重繪窗體標題欄 DrawMenuBar hWndForm End Sub "mdThickfram" 模塊代碼 Option Explicit ' 此過程為工作表內按鈕調用 Sub ShowThickFramForm() frmThickFram.Show End Sub 1文件名稱 | 1下載鏈接 | 1禁用窗體關閉按鈕.zip | http://pan.baidu.com/s/1i39T4X3 |
Excel整體界面趨于平面化,顯得清新簡潔。流暢的動畫和平滑的過渡,帶來不同以往的使用體驗。 |