|
楼主 |
发表于 2018-9-19 22:31
|
显示全部楼层
您好,我把您写的代码放进了我找的代码里,运行出现了错误,如果只是单个宏(在其他工作表),运行是好的,如果可以,麻烦您帮我看看问题在哪?- Sub 批量操作()
- Application.ScreenUpdating = False
- Dim wb As Excel.Workbook
- f = Dir(ThisWorkbook.Path & "\*.xls*") '生成查找EXCEL的目录,可以适应不同版本
- Do While f <> "" '在目录中循环
- If f <> ThisWorkbook.Name Then '如果不是打开的工作簿
- Set wb = Workbooks.Open(ThisWorkbook.Path & "" & f) '依次打开目录工作薄
- With wb.Worksheets(1)
- .Rows("1:6").Select
- Selection.Delete Shift:=xlUp
- X = Cells(Rows.Count, 1).End(xlUp).Row
- Rows(X).Delete
- Range("A1:C1").Select
- With Selection
- .HorizontalAlignment = xlGeneral
- .VerticalAlignment = xlBottom
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = True
- End With
- Selection.UnMerge
- Columns("A:A").Select
- Selection.Delete Shift:=xlToLeft
- Columns("B:B").Select
- Selection.Cut
- Columns("A:A").Select
- Selection.Insert Shift:=xlToRight
- Columns("A:A").Select
- Selection.Delete Shift:=xlToLeft
- Cells.Select
- Selection.Replace What:="/", Replacement:="", LookAt:=xlPart, _
- SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
- ReplaceFormat:=False
- Dim i As Integer
- Dim y As Integer
- y = [iv1].End(xlToLeft).Column
- For i = y To 1 Step -1
- If Cells(65536, i).End(xlUp).Row = 2 Then
- Debug.Print i
- Columns(i).Delete
- End If
- Next
- Arr = [a2].CurrentRegion
- For m = 2 To UBound(Arr)
- For n = 2 To UBound(Arr, 2)
- If Len(Arr(m, n)) = 0 Then Arr(m, n) = -1
- Next
- Next
- [a2].CurrentRegion = Arr
- Sheets.Add After:=ActiveSheet
- Sheets("完成学分情况").Select
- End With
- wb.Close True '关闭打开的工作薄
- End If
- f = Dir
- Loop '结束循环
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|