Problem a friend has getting Error 438 all the time

断了今生、忘了曾经 提交于 2021-02-17 05:21:10

问题


I sent a friend a workbook with a macro that includes some sorting. When he tries it he gets:

Run-time error '438' Object doesn't support this property or method.

He clicks Debug to see the offending code and is taken to a line or two of (fairly simple) data sorting. The text that gets highlighted is:

ActiveWorkbook.Worksheets("Data Set").Sort.SortFields.Add2 Key:=Range( _
    "H2:H8065"), SortOn:=x1SortOnValues, Order:=x1Descending, DataOption:= _
    x1SortNormal 

Those 3 lines are it, part of a larger sorting, and then copy/paste etc. Works fine for me (Office 365). He, in Chicago - I am in the UK - has maybe an older version of Windows.

Similar sorting occurs in other files I've sent him, and they work fine. Would anyone know what I could alter to get rid of this 438 thing? Thanks for any help.


回答1:


Use SortFields.Add instead of the newer version SortFields.Add2, which is not supported in older versions of Excel.

From the .Add2 documentation:

This API includes support for sorting off a SubField from data types, such as Geography or Stocks. You can also use the Add method if sorting by a data type is not needed.

... and you are not sorting by data type, so use .Add.



来源:https://stackoverflow.com/questions/60889069/problem-a-friend-has-getting-error-438-all-the-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!