什么是sort2的add2 [英] What is add2 for sortfields

查看:702
本文介绍了什么是sort2的add2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用宏记录器对ListObject(表)进行排序时,它会产生:

When I use the macro recorder on sorting a ListObject (table), it produces:

ActiveWorkbook.Worksheets("Output").ListObjects("Table4").Sort.SortFields.Add2

在我的Excel版本中可以很好地工作.但是,这不能在其他Excel上编译.将其更改为.Add即可解决问题.

which works perfectly fine in my version of Excel. However, this doesn't compile on other Excels. Changing it to .Add solves the problem.

Google表示.Add2仅存在于ChartObjects中-但记录器为ListObject记录了它-并且它在这里有效,但在其他Excel(相同版本)中则无效.

Google says that .Add2 only exists for ChartObjects - but the recorder records it for a ListObject - and it works here but not in the other Excel (same version).

什么是.Add2?为什么我的Excel认为这是正确的方法?

What is .Add2? Why does my Excel think that's the correct way?

推荐答案

这不是答案;我想补充一下我发现的内容.也许应该(但无法)使用评论.

This is not an answer; I'd like to add what I found out. Should have used comment maybe (but unable to).

  • I can confirm Excel 365 Business macro recorder records Sort.SortFields.Add2 if you define a filter on either a ListObject or a Worksheet.
  • I can not confirm the macro does not work on same Excel version on another machine (for me it works; tested with Excel 16.0.10228.20080 32Bit).
  • The Add2 method is not documented on MSDN for the SortFields Collection (1), but for serveral other objects (so "only for ChartObject" is not corrrect).
  • The VBA object library (of my Excel version, see above) lists Add2 as Function in SortFields Class; the only difference between Add and Add2 seems to be that Add2 has one more optional paramter [SubField].

结论:我想(但这只是一个猜测!)Add2 to是功能的扩展,出于兼容性原因,该功能已使用新名称实现.在这种情况下,宏记录器可能总是使用最新功能. 除非需要SubField参数,否则您可以使用Add.

Conclusion: I guess (but this is only a guess!) that Add2 to is an expansion in functionality that has been implemented with a new name for compatibility reasons. Maybe the macro recorder always uses the most recent function in such a case. Yor can use Add unless you need the SubField parameter.

我仍然想加深了解,就像埃德温·埃德勒(Edwin Ederle)要求的那样.由于完全相同的情况,我碰到了这篇文章:使用记录器来学习编码排序功能,对Add2感到疑惑,并询问google.如果您搜索"vba sortfields add2" =>,那么这个问题是第一个Google匹配(其中之一)=>也许值得在此处提供更多信息.

I still like to get a deeper understanding, like Edwin Ederle asked for. I came across this post because of exact the same situation: using the recorder to learn about coding sort functions, wondering about Add2, and asking google. This question is (one of) the first google hit(s) if you search for "vba sortfields add2" => maybe worth giving some more information here.

这篇关于什么是sort2的add2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆