繁体   English   中英

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

[英]Excel VBA Application run-time error 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项目窗口上的“模块”节点,单击“插入模块”,然后将宏粘贴到新模块中(确保删除在工作表级别记录的宏)。

希望这可以帮助!

问候,埃比

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM