- 需在删除指定文件夹外部 , 新建excel用于运行宏命令
Sub Del_Col()
Application.DisplayAlerts = False '做操作时所有提示信息都忽略
Dim myFiles As String
Dim myExcels As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
.AllowMultiSelect = False
.Title = "请选择要删除列的文件所在文件夹"
myFiles = .SelectedItems(1)
End With
myExcels = Dir(myFiles & "\" & "*.xls*")
Do While Len(myExcels) <> 0
Workbooks.Open (myFiles & "\" & myExcels)
Worksheets(1).Columns("A:A").Select 'Worksheets(1)中的1代表删除每个excel中最左侧的工作簿,Columns("A:A")中"A:A"代表删除D列,如果删除其他列或者连续的几列,修改该值。
Selection.Delete Shift:=xlToLeft
ActiveWorkbook.Save
Workbooks(2).Close
myExcels = Dir
Loop
Application.DisplayAlerts = True
MsgBox "删除完成"
End Sub