判断Excel单元格是否处于编辑状态

以下代码就是当处于编辑状态时在Excel的状态栏上显示 正处于编辑状态……
' **********************************************************************************************************
'
**********************************************************************************************************
'
//取得类名
Private   Declare   Function  GetClassName _
    
Lib   " user32 "  _
    
Alias   " GetClassNameA "  ( _
        
ByVal  hwnd  As   Long , _
        
ByVal  lpClassName  As   String , _
        
ByVal  nMaxCount  As   Long ) _
As   Long
' //设置钩子函数
Public   Declare   Function  SetWindowsHookEx _
    
Lib   " user32 "  _
    
Alias   " SetWindowsHookExA "  ( _
        
ByVal  idHook  As   Long , _
        
ByVal  lpfn  As   Long , _
        
ByVal  hmod  As   Long , _
        
ByVal  dwThreadId  As   Long ) _
As   Long
' //结束钩子
Public   Declare   Function  UnhookWindowsHookEx _
    
Lib   " user32 "  ( _
        
ByVal  hHook  As   Long ) _
As   Long
' //下一个钩子
Public   Declare   Function  CallNextHookEx _
    
Lib   " user32 "  ( _
        
ByVal  hHook  As   Long , _
        
ByVal  nCode  As   Long , _
        
ByVal  wParam  As   Long , _
        lparam 
As  Any) _
As   Long
' //取得当前线程的ID
Public   Declare   Function  GetCurrentThreadId _
    
Lib   " kernel32 "  () _
As   Long

Public   Const  HCBT_SETFOCUS  =   9
Public   Const  WH_CBT  =   5
Public  IHook  As   Long
Public  IThreadId  As   Long
Public  ClassName  As   String
' -------设置钩子-----------
Public   Sub  EnableHook()
    
If  IHook  =   0   Then
        IThreadId 
=  GetCurrentThreadId
        IHook 
=  SetWindowsHookEx(WH_CBT,  AddressOf  HookProc, Application.Hinstance, IThreadId)
    
End   If
End Sub
' -------取消钩子-----------
Public   Sub  FreeHook()
    
If  IHook  <>   0   Then
        
Call  UnhookWindowsHookEx(IHook)
        IHook 
=   0
    
End   If
End Sub
' ---------回调----------------
Public   Function  HookProc( ByVal  nCode  As   Long ByVal  wParam  As   Long ByVal  lparam  As   Long As   Long
    
If  nCode  <   0   Then
        HookProc 
=  CallNextHookEx(IHook, nCode, wParam, lparam)
        
Exit Function
    
End   If
    
If  nCode  =  HCBT_SETFOCUS  Then
        ClassName 
=   String ( 255 Chr ( 0 ))
        GetClassName wParam, ClassName, 
255
        ClassName 
=   Left (ClassName,  InStr (ClassName, vbNullChar)  -   1 )
        
If  ClassName  =   " EXCEL< "   Or  ClassName  =   " EXCEL6 "   Then
            Application.StatusBar 
=   " 正处于编辑状态…… "
        
Else
            Application.StatusBar 
=   False
        
End   If
    
End   If
    HookProc 
=  CallNextHookEx(IHook, nCode, wParam, lparam)
End Function

转载于:https://www.cnblogs.com/wangminbai/archive/2008/02/20/1075339.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值