“重置Excel”;查找并替换“;对话框参数
如何以编程方式将Excel“重置Excel”;查找并替换“;对话框参数,excel,vba,Excel,Vba,如何以编程方式将ExcelFind and Replace对话框参数重置为默认值(“查找内容”、“替换为”、“内部”、“搜索”、“查找”、“匹配大小写”、“匹配整个单元格内容”) 我正在使用Application.FindFormat.Clear和Application.ReplaceFormat.Clear重置查找和替换单元格格式 有趣的是,在使用expression.Replace(FindWhat,ReplaceWhat,after,MatchCase,WholeWords)之后,Find
Find and Replace
对话框参数重置为默认值(“查找内容”、“替换为”、“内部”、“搜索”、“查找”、“匹配大小写”、“匹配整个单元格内容”)
我正在使用Application.FindFormat.Clear
和Application.ReplaceFormat.Clear
重置查找和替换单元格格式
有趣的是,在使用
expression.Replace(FindWhat,ReplaceWhat,after,MatchCase,WholeWords)
之后,FindWhat
字符串显示在Find and Replace
对话框中,而不是ReplaceWhat
参数中。您可以使用以下命令打开填充字段的“Replace”对话框:
Application.Dialogs(xlDialogFormulaReplace).Show-arguments here-
参数列表是
查找文本、替换文本、查找、查找方式、活动单元格、匹配大小写、匹配字节
到目前为止,我发现“点击”按钮的唯一方法是使用SendKey
经过大量的研究和测试,我现在确切地知道您想要做什么,但我认为这是不可能做到的(没有SendKey)。Excel中似乎存在一个错误,无论您尝试将其设置为什么,它都不会重置替换值(从VBA) 我确实发现有人在MSDN上发布这种“更快”的方式,所以你可以试试
您可以使用此宏重置查找和替换。不幸的是,您必须同时调用这两个参数,因为每个参数都有一个或两个唯一的参数,因此,如果您想重置所有参数,您将陷入困境。没有“重置”,所以我找到的唯一方法是使用默认参数执行伪查找和替换
Sub ResetFind()
Dim r As Range
On Error Resume Next 'just in case there is no active cell
Set r = ActiveCell
On Error Goto 0
Cells.Find what:="", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False
Cells.Replace what:="", Replacement:="", ReplaceFormat:=False
If Not r Is Nothing Then r.Select
Set r = Nothing
End Sub
无需使用sendkeys,您可以轻松引用重置对话框值所需的值
Sub ResetFindReplace()
'Resets the find/replace dialog box options
Dim r As Range
On Error Resume Next
Set r = Cells.Find(What:="", _
LookIn:=xlFormulas, _
SearchOrder:=xlRows, _
LookAt:=xlPart, _
MatchCase:=False)
On Error GoTo 0
'Reset the defaults
On Error Resume Next
Set r = Cells.Find(What:="", _
LookIn:=xlFormulas, _
SearchOrder:=xlRows, _
LookAt:=xlPart, _
MatchCase:=False)
On Error GoTo 0
End Sub
我测试了这个,它是有效的。我从几个地方借了零件
Sub RR0() 'Replace Reset & Open dialog (specs: clear settings, search columns, match case)
'Dim r As RANGE 'not seem to need
'Set r = ActiveCell 'not seem to need
On Error Resume Next 'just in case there is no active cell
On Error GoTo 0
Application.FindFormat.Clear 'yes
Application.ReplaceFormat.Clear 'yes
Cells.find what:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext
Cells.Replace what:="", Replacement:="", ReplaceFormat:=False, MatchCase:=True 'format not seem to do anything
'Cells.Replace what:="", Replacement:="", ReplaceFormat:=False 'orig, wo matchcase not work unless put here - in replace
'If Not r Is Nothing Then r.Select 'not seem to need
'Set r = Nothing
'settings choices:
'match entire cell: LookAt:=xlWhole, or: LookAt:=xlPart,
'column or row: SearchOrder:=xlByColumns, or: SearchOrder:=xlByRows,
Application.CommandBars("Edit").Controls("Replace...").Execute 'YES WORKS
'Application.CommandBars("Edit").Controls("Find...").Execute 'YES same, easier to manipulate
'Application.CommandBars.FindControl(ID:=1849).Execute 'YES full find dialog
'PROBLEM: how to expand options?
'SendKeys ("%{T}") 'alt-T works the first time, want options to stay open
Application.EnableEvents = True 'EVENTS
End Sub
非常感谢。我希望在VBA中使用查找和替换后进行清理。希望有一个不需要弹出对话框的解决方案。显示方法后不知道参数。至少让我不用使用SendKeys(蛮力)。南非约翰内斯堡。