excel - 复制的宏表打开原始工作簿
问题描述
我将一个工作表拆分为大约 30 个工作表(全部在单独的工作簿中)。我为希望复制到输出工作表的原始工作表编写了一个简单的宏。我遇到的问题是,当我在输出工作表中运行宏时,它会打开原始工作簿。有人可以帮我解决这个问题,以便在复制工作表时,宏将在不打开其他工作簿的情况下工作?
这是我要复制的宏 - 它只是折叠已小计的数据然后对其进行排序(我将这些工作簿发送给不擅长 excel 的人并试图使其尽可能简单):
Sub collapse_sort1()
Dim sort_status As String
Dim r1 As Range
Set r1 = ActiveSheet.Range("L1")
ActiveSheet.Outline.ShowLevels RowLevels:=2
ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Clear
If r1.Value = "D" Then
ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add _
Key:=Range("L2:L3000"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
r1.Value = "A"
Else
ActiveWorkbook.ActiveSheet.AutoFilter.Sort.SortFields.Add _
Key:=Range("L2:L3000"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
r1.Value = "D"
End If
End Sub
解决方案
推荐阅读
- hybris - 将 Backoffice 中的 Default Extended Multi Reference Editor 中的类别缩小到给定类别的子类别
- c++ - 在 c++ 中使用 std::getline() 接受带空格的输入
- c++ - C++ 删除所有文件和子文件夹,但保留目录本身
- quarkus - quarkus 热部署不保存文件
- django - Django Rest Framework - 无法避免空字段在响应中被序列化
- python - 如何在 csv 文件中写入/覆盖
- c++ - 使用模板排序的默认谓词。C++
- linux - 使用函数的彩色 bash 提示符
- heroku - 如何从 Heroku CI 的 in-dyno postgres 实例中的应用程序自动导入转储?
- node.js - 尝试将项目添加到购物车时,项目数组为空