【问题标题】:Excel VBA Application run-time error 1004Excel VBA 应用程序运行时错误 1004
【发布时间】:2018-04-05 20:36:02
【问题描述】:

我们提供了一个 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

【问题讨论】:

    标签: vba excel


    【解决方案1】:

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

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

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

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

    希望这会有所帮助!

    问候, 埃比

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多