Excel VBA 应用程序运行时错误 1004



我们提供了一个excel-vba文件,该文件在某些计算机上运行良好,但在某些计算机上会生成以下错误:运行时错误1004,应用程序定义或用户定义错误,顺序如下:

sheetChoiceList.Sort.SortFields.Add key:=ThisWorkbook.Names("ChoiceList_AllChoices").RefersToRange.Columns(6), _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal

子:

Sub SortChoiceListForCurrentQuestionChoiceList()
' Sorts the Choice List based on the question type of the current question
' A formula in the sheet determines if the choice is applicable to the current question, returning a TRUE/FALSE
' A dyanamic named range uses the count of TRUE values to determine the number of rows extending down from row 2
' The sort is necessary to ensure that the TRUE values start on row 2
sheetChoiceList.Sort.SortFields.Clear
sheetChoiceList.Sort.SortFields.Add key:=ThisWorkbook.Names("ChoiceList_AllChoices").RefersToRange.Columns(6), _
                                                               SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With sheetChoiceList.Sort
    .SetRange ThisWorkbook.Names("ChoiceList_AllChoices").RefersToRange
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
End Sub

这可能是由于各种原因造成的。

1(可能是,因为宏是在工作表级别记录的。右键单击VBA项目窗口上的模块节点,单击插入模块,然后将宏粘贴到新模块中(确保删除在工作表级别记录的宏(。

2(查看excel中是否有任何受保护的单元格或工作表,如果有,请删除保护

3(检查工作表级别是否记录了任何宏。如果工作表级别有任何宏,请将它们移动到模块中。右键单击VBA项目窗口上的模块节点,单击插入模块,然后将宏粘贴到新模块中(确保删除在工作表级别记录的宏(。

希望这有帮助!

问候埃比

最新更新