by chijanzen on 五月 24th, 2009 | View: 3,145 views
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _ ByVal nCmdShow As Long) As LongPrivate Const SW_HIDE = 0Private Const SW_SHOW = 5 Private Sub Workbook_Activate() ShowWindow SbarHwnd, SW_SHOWEnd Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) DestroyWindow SbarHwndEnd Sub Private Sub Workbook_Deactivate() ShowWindow SbarHwnd, SW_HIDEEnd Sub Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, _ ByVal Target As Range, Cancel As Boolean) Cancel = TrueEnd Sub Private Sub Workbook_Open() SetFormulaBarEnd Sub Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _ ByVal Target As Range) SetText 0, Target(1, 1).ValueEnd Sub
Sub ProtectSheet() '刪除先前定義的允許使用者可編輯範圍(Title:="Range1") UnProtectSheet '工作表處於保護狀態時仍能修改 Cells.Locked = False '工作表處於保護狀態時隱藏公式 Cells.FormulaHidden = True '可在受保護工作表中編輯所有儲存格 ActiveSheet.Protection.AllowEditRanges.Add Title:="Range1", Range:=Cells '保護工作表,但是允許所有的編輯功能 ActiveSheet.Protect _ AllowFormattingCells:=True, AllowFormattingColumns:=True, _ AllowFormattingRows:=True, AllowInsertingColumns:=True, _ AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _ AllowDeletingColumns:=True, AllowDeletingRows:=True, _ AllowSorting:=True, AllowFiltering:=True, _ Password:="chijanzen"End Sub Sub UnProtectSheet() On Error Resume Next ActiveSheet.Unprotect ("chijanzen") ActiveSheet.Protection.AllowEditRanges("Range1").Delete Error = 0End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _ lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function InitCommonControlsEx Lib "comctl32.dll" _ (lpInitCtrls As tagInitCommonControlsEx) As BooleanPrivate Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _ ByVal lpsz2 As String) As LongPrivate Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, _ lpRect As RECT) As LongPrivate Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" _ (ByVal dwExStyle As Long, ByVal lpClassName As String, _ ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, _ ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _ ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, _ ByRef lpParam As Any) As LongPublic Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As Long'// Windows 訊息和風格Public Const WM_USER = &H400Public Const WS_VISIBLE = &H10000000Public Const WS_CHILD = &H40000000'// 進度條的風格和訊息'Public Const PROGRESS_CLASS = "msctls_progress32"'Public Const PBM_SETPOS = (WM_USER + 2)'Public Const PBM_SETBARCOLOR = (WM_USER + 9)'// Control 控制的訊息Public Const CCM_FIRST = &H2000Public Const CCM_SETBKCOLOR = (CCM_FIRST + 1)Public Const SB_SETBKCOLOR = CCM_SETBKCOLOR'Public Const PBS_SMOOTH = 1Public hwnd As Long, SbarHwnd As Long, pbhWnd As LongPrivate Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePrivate Type tagInitCommonControlsEx lngSize As Long lngICC As LongEnd Type Sub SetFormulaBar() Dim hWndP As Long Dim rct As RECT, i As Long Const SBARS_SIZEGRIP = &H100 Const CCS_BOTTOM = &H3& Const ICC_BAR_CLASSES = &H4 Const STATUSCLASSNAME = "msctls_statusbar32" 'Status bar 狀態條 Const SB_SETPARTS = WM_USER + 1 '此消息能幫助應用程序自定義私有消息; Dim iccex As tagInitCommonControlsEx, meHwnd As Long Dim adwParts(2) As Long, dwRtn As Long, X As Single With iccex .lngSize = LenB(iccex) .lngICC = ICC_BAR_CLASSES End With Call InitCommonControlsEx(iccex) hwnd = FindWindow("XLMAIN", Application.Caption) hWndP = FindWindowEx(hwnd, 0, "EXCEL<", vbNullString) GetClientRect hWndP, rct X = rct.Right - rct.Left dwRtn = WS_VISIBLE Or WS_CHILD Or CCS_BOTTOM ' Or SBARS_SIZEGRIP '小三角形 SbarHwnd = CreateWindowEx(0, STATUSCLASSNAME, "", _ dwRtn, 0, 0, 0, 0, hWndP, 0, 0, 0) adwParts(0) = X SendMessage SbarHwnd, SB_SETPARTS, ByVal 1, adwParts(0) SetText 0, ActiveCell.ValueEnd Sub Sub SetText(Optional bPart As Byte = 0, Optional sText As String = "") Const SB_SETTEXT = (WM_USER + 1) SendMessage SbarHwnd, SB_SETTEXT, ByVal bPart, ByVal sTextEnd Sub
ActiveSheet.Protection.AllowEditRanges("Range1").Delete 刪除允許編輯儲存格的鎖定範圍 此範例VBE的密碼:chijanzen
ActiveSheet.Protection.AllowEditRanges("Range1").Delete
刪除允許編輯儲存格的鎖定範圍
Popularity: 52%
Аффтар - аццкий сотона !! Пеши исчо !!
Name: « Required
Email Address: « Required
Website URL: « Optional
Type your message here...
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
發表於討論區 一般訪客留言 於 九月 7, 2010
發表於討論區 一般訪客留言 於 六月 6, 2010
發表於討論區 API函數 於 一月 19, 2010
發表於討論區 技術交流 於 一月 13, 2010
發表於討論區 一般訪客留言 by reader 於 九月 7, 2010 at 9:31 下午
發表於討論區 一般訪客留言 by kenjo 於 六月 6, 2010 at 2:55 下午
發表於討論區 API函數 by chijanzen 於 一月 19, 2010 at 1:50 下午
發表於討論區 API函數 by chijanzen 於 一月 19, 2010 at 1:11 下午
發表於討論區 技術交流 by chijanzen 於 一月 13, 2010 at 5:43 下午
GEOLOC
姓名:超級皮卡丘
網路化名: chijanzen、中國龍
經歷:
Аффтар - аццкий сотона !! Пеши исчо !!