1

我有 2 个环境,一个是企业版MS Office 365 应用程序,另一个是专业版 plus 2016。 宏代码在企业版 MS Office 365 应用程序中运行良好,但在 Selection.Find 功能的专业版 plus 2016 中面临“下标超出范围”异常.

调试时注意到 xlFormulas2 为空,这可能导致错误,但不确定为什么 xlFormulas2 在专业加 2016 中为空,但在其他环境中正常工作的 -4185。

Sub AA_01_Spring_China_Individual()
sNumber = InputBox("Which week you would like to update?", "Week No:")
sResponse = "Week " & sNumber

Sheets("BD Calls").Select
Columns("A:A").Select
Selection.Find(What:="Beijing", After:=ActiveCell, LookIn:=xlFormulas2, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

在此处输入图像描述

4

1 回答 1

1

可能xlFormulas2适用于 Office 365。要使查找在这两种情况下都能正常工作,您可以避免类似 ...

Sub Macro1()

Dim foundCl As Range
On Error Resume Next
Set foundCl = Selection.Find(What:="Beijing", After:=ActiveCell, LookIn:=xlFormulas2, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False)
If foundCl Is Nothing Then
Set foundCl = Selection.Find(What:="Beijing", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
End If
On Error GoTo 0

Debug.Print foundCl.Address
foundCl.Activate
End Sub
于 2021-07-16T03:12:36.540 回答