'/// API ///
Private Declare Function FindWindowEx& Lib "user32.dll" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String)
Private Declare Function PostMessage& Lib "user32.dll" _
Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long)
'/// Messages Window ///
Const WM_LBUTTONDOWN As Long = &H201&
Const WM_LBUTTONUP As Long = &H202&
Sub ClearOfficeClipboard()
Dim CB As CommandBar
Dim Etat As Boolean
Dim hExcel2&
Dim hWindow&
Dim hParent&
Dim hClip&
Dim coord&
On Error GoTo Erreur
Application.ScreenUpdating = False
Set CB = Application.CommandBars("Task Pane")
With CB
.Position = msoBarRight
Etat = .Visible
End With
If Not Etat Then Application.CommandBars(1).Controls(2).Controls(5).Execute
hExcel2 = FindWindowEx(Application.hWnd, hExcel2, "EXCEL2", vbNullString)
If hExcel2 = 0 Then Exit Sub
hWindow = FindWindowEx(hExcel2, hWindow, "MsoCommandBar", CB.NameLocal)
If hWindow Then
hParent = hWindow
hWindow = 0
hWindow = FindWindowEx(hParent, hWindow, "MsoWorkPane", vbNullString)
If hWindow Then
hParent = hWindow
hWindow = 0
hClip = FindWindowEx(hParent, hWindow, "bosa_sdm_XL9", vbNullString)
End If
End If
If hClip > 0 Then
coord& = 25 * 65536 + 125
Call PostMessage(hClip, WM_LBUTTONDOWN, 0&, coord&)
Call PostMessage(hClip, WM_LBUTTONUP, 0&, coord&)
End If
If Not Etat Then CB.Visible = False
Erreur:
Application.ScreenUpdating = True
End Sub