ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 名课 - Power BI数据分析与可视化实战 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
Python自动化办公应用大全 Excel 2021函数公式学习大典 Kutools for Office 套件发布 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: everbest2015

[求助] 关于 Application.CutCopyMode = False

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2025-6-17 14:54 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
ykcbf1100 发表于 2025-6-17 11:58
8楼代码还不行的话,再试试使用 Windows API 清空剪贴板

感谢大佬  实测没效果  依然感谢

TA的精华主题

TA的得分主题

 楼主| 发表于 2025-6-17 14:54 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

感谢,测试貌似没效果 有可能是没太懂怎么用

TA的精华主题

TA的得分主题

发表于 2025-6-17 15:00 | 显示全部楼层
ISS001大师所说要利用IUIAutomationCilent
  1. Sub 清空office剪贴板() '添加引用:IUIAutomationCilent
  2.     On Error Resume Next
  3.     ThisWorkbook.VBProject.References.AddFromFile "UIAutomationCore.dll"
  4.     Call ClearClip '清空Office剪贴板
  5. End Sub
  6. Sub ClearClip()
  7.     'On Error Resume Next
  8.     Dim AutomationObj As IUIAutomation
  9.     Dim WindowElement As IUIAutomationElement
  10.     Dim clearButton As IUIAutomationElement
  11.     Application.ScreenUpdating = True
  12.     Application.DisplayClipboardWindow = True
  13.     Set ExcelSheet = CreateObject("Excel.Sheet")
  14.     ExcelSheet.Application.Visible = True
  15.     Set AutomationObj = New CUIAutomation
  16.     Set WindowElement = AutomationObj.ElementFromHandle(ByVal Application.hwnd)
  17.     Dim iCond As IUIAutomationCondition
  18.     Set iCond = AutomationObj.CreatePropertyCondition(UIA_NamePropertyId, "全部清空")
  19.     Set clearButton = WindowElement.FindFirst(TreeScope_Subtree, iCond)
  20.     Dim InvokePattern As IUIAutomationInvokePattern
  21.     If clearButton.CurrentName = "全部清空" Then
  22.         Set InvokePattern = clearButton.GetCurrentPattern(UIA_InvokePatternId)
  23.         InvokePattern.Invoke
  24.     End If
  25.     Application.Wait Now + TimeSerial(0, 0, 2)
  26.     ExcelSheet.Close
  27. End Sub
复制代码

方法是对的

TA的精华主题

TA的得分主题

发表于 2025-6-17 18:52 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
everbest2015 发表于 2025-6-17 14:54
感谢,测试貌似没效果 有可能是没太懂怎么用

得谷歌

2.png
8.gif

office剪切板全部清空.zip

1.22 KB, 下载次数: 13

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2025-6-17 20:35 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

优秀!!!!!!!!!!!!!!!!!!!!!!!!!1

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2025-6-17 21:26 来自手机 | 显示全部楼层
本帖最后由 lss001 于 2025-6-19 06:48 编辑

[quote]


TA的精华主题

TA的得分主题

发表于 2025-6-19 09:32 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
模拟手工清空Office剪贴板,简单粗暴了点,
  1. Type POINTAPI
  2.     x As Long
  3.     y As Long
  4. End Type
  5. Type RECT
  6.     Left As Long
  7.     Top As Long
  8.     Right As Long
  9.     Bottom As Long
  10. End Type
  11. #If VBA7 Then
  12.     Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As LongPtr, ByVal hWndChildAfter As LongPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As LongPtr
  13.     Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
  14.     Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
  15.     Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As LongPtr)
  16. #Else
  17.     Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
  18.     Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  19.     Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
  20.     Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
  21. #End If

  22. Sub ClearClipboard()
  23.     #If VBA7 Then
  24.         Dim hwnd As LongPtr
  25.     #Else
  26.         Dim hwnd As Long
  27.     #End If
  28.     Dim blVisible As Boolean
  29.     Application.ScreenUpdating = True
  30.     With Application.CommandBars("Office Clipboard")
  31.         blVisible = .Visible
  32.         If Not blVisible Then .Visible = True: DoEvents
  33.         hwnd = FindClipboardWindow()
  34.         If hwnd = 0 Then Exit Sub
  35.         Dim RECT As RECT, pt As POINTAPI
  36.         GetWindowRect hwnd, RECT
  37.         ' 计算"全部清空"按钮坐标(左上角偏移)
  38.         
  39.         If RECT.Right - RECT.Left > 220 Then
  40.             '"全部清空"按钮水平排列在"全部粘贴"按钮的右侧
  41.             pt.x = RECT.Left + 140
  42.             pt.y = RECT.Top + 20
  43.         Else
  44.             '"全部清空"按钮纵向排列在"全部粘贴"按钮的下方
  45.             pt.x = RECT.Left + 62
  46.             pt.y = RECT.Top + 53
  47.         End If
  48.         '    模拟鼠标单击"全部清空"按钮
  49.         LeftClickOnPoint pt
  50.         .Visible = blVisible
  51.     End With
  52. End Sub
  53. #If VBA7 Then
  54. Private Function FindClipboardWindow() As LongPtr
  55.     Dim hwnd As LongPtr
  56. #Else
  57. Private Function FindClipboardWindow() As Long
  58.     Dim hwnd As Long
  59. #End If
  60.     hwnd = FindWindow("XLMAIN", ThisWorkbook.Application.Caption)
  61.     hwnd = FindWindowEx(hwnd, 0, "EXCEL2", vbNullString)
  62.     hwnd = FindWindowEx(hwnd, 0, "MsoCommandBar", "Office 剪贴板")
  63.     hwnd = FindWindowEx(hwnd, 0, "MsoWorkPane", vbNullString)
  64.     FindClipboardWindow = hwnd
  65. End Function
复制代码

TA的精华主题

TA的得分主题

发表于 2025-6-19 10:48 | 显示全部楼层
上面落下了一个子过程,补丁一下:
  1. Private Sub LeftClickOnPoint(pt As POINTAPI)
  2.     SetCursorPos pt.x, pt.y
  3.     mouse_event &H2, 0, 0, 0, 0 ' MOUSEEVENTF_LEFTDOWN
  4.     mouse_event &H4, 0, 0, 0, 0 ' MOUSEEVENTF_LEFTUP
  5.     DoEvents
  6. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2025-6-19 23:16 来自手机 | 显示全部楼层
ggmmlol 发表于 2025-6-19 10:48
上面落下了一个子过程,补丁一下:

建议看看以下博客文章
https://www.cnblogs.com/wangminbai/archive/2008/04/25/1169808.html
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-12-25 06:10 , Processed in 0.035125 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表