【问题标题】:Converting Excel 2007 VBA to Excel 2003将 Excel 2007 VBA 转换为 Excel 2003
【发布时间】:2012-06-19 14:48:56
【问题描述】:

我正在尝试调整我为 Excel 2007 编写的 xla 加载项,以便在 Excel 2003 中工作。我已对大部分问题进行了排序,但我无法找到对工作表中的字段进行排序的方法。我有需要按创建日期顺序排序的数据行(其值在 H 列中)。这是我使用的 Excel 2007 代码:

        'sort issues into descending order
        Sheets("In Progress").Sort.SortFields.Clear
        Sheets("In Progress").Sort.SortFields.Add _
                Key:=Range("H:H"), _
                SortOn:=xlSortOnValues, _
                Order:=xlDescending, _
                DataOption:=xlSortNormal
        With Sheets("In Progress").Sort
            .SetRange Range("A2:M" & rowCount - 1)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With

谁能帮我让它在 Excel 2003 上工作?

【问题讨论】:

  • 您遇到什么错误?什么不起作用?您是否尝试逐步删除某些代码行?

标签: excel vba excel-2003


【解决方案1】:

最好的办法是把代码写成低版本,这样它就可以在所有版本中运行。

我将使用此代码进行排序,该代码适用于所有版本。

With Sheets("In Progress")
    .Range("A2:M" & rowCount - 1).Sort Key1:=.Range("A2"), _
    Order1:=xlDescending, Header:=xlNo, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
End With

【讨论】:

  • 干杯,这似乎成功了!非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-07
相关资源
最近更新 更多