|
楼主 |
发表于 2023-3-24 18:12
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
不用 vbs ,用 API 异步 关闭对话框
- #If VBA7 Then
- Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As Long
- Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongPtr, ByVal uIDEvent As Long) As Long
- Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
- ByVal bScan As Byte, _
- ByVal dwFlags As Long, _
- ByVal dwExtraInfo As LongPtr)
- #Else
- Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal uIDEvent As Long) As Long
- Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
- #End If
- Const KEYEVENTF_KEYUP = &H2
- Const VK_ESCAPE = &H1B
- Sub 一键整个工作簿替换()
- '''异步关闭窗口
- Call ClosePrintPreview(Close_In_HowMany_Seconds_FromNow:=0) '<== Close PPreview in 0 sconds - Change argument value to suit
- Application.Dialogs(xlDialogFormulaFind).Show , 2, 2
- ThisWorkbook.Activate
- '''被替换内容 What ,,新内容 Replacement
- Cells.Replace What:="bbb", Replacement:="aaa", LookAt:=xlPart, SearchOrder _
- :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
- MsgBox "已全部替换!!!"
- End Sub
- Private Sub ClosePrintPreview(ByVal Close_In_HowMany_Seconds_FromNow As Long)
- Call SetTimer(Application.hwnd, 0, Abs(Close_In_HowMany_Seconds_FromNow) * 1000, AddressOf CloseNow)
- '按下 ESC
- keybd_event VK_ESCAPE, 0, 0, 0
- '释放 ESC
- keybd_event VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0
- End Sub
- Private Sub CloseNow()
- Call KillTimer(Application.hwnd, 0)
- End Sub
复制代码
|
|