0

当 excel 宏未打开新工作表时,排序命令有效。如果 excel 宏试图操作由宏打开的工作表,则相同的排序命令不起作用。

With ActiveWorkbook.Worksheets("Sheet").Sort
  .SetRange Range("A1:D" & replacementRow - 1)
  .Header = xlNo
  .MatchCase = False
  .Orientation = xlTopToBottom
  .SortMethod = xlPinYin
  .Apply
End With

用于打开工作簿的语句

Workbooks.Open (Cells(1, 1))
4

1 回答 1

1

我假设您有指向 Cell (1,1) 中工作簿的链接?如果是这样尝试:

Dim wb As Workbook
Set wb = Workbooks.Open(Cells(1, 1))

With wb.Worksheets("Sheet1").Sort
  .SetRange Range("A1:D" & replacementRow - 1)
  .Header = xlNo
  .MatchCase = False
  .Orientation = xlTopToBottom
  .SortMethod = xlPinYin
  .Apply
End With
于 2012-11-11T17:32:21.740 回答