阅: 4273 | 回: 3

-
积分:1
-
财富值:1.0
-
身份:普通用户
用VBA实现批量删除指定文件夹下工作表表头,如图所示,删除前与删除后效果。

但在运行时出错

(文件夹内工作薄模拟了上报的数据,只能保证结构相同,数据质量得不到保证,要求在这种情况下运行),请各位高手帮我看看代码错在哪儿?
补充内容(2015-7-30 15:32:23):
Sub deleteheadline()
Dim Fso As Object, Folder As Object
Dim i&, n&, a, b, Wb As Workbook, p$
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & "\"
If .Show = False Then Exit Sub
p = .SelectedItems(1)
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Fso = CreateObject("Scripting.FileSystemObject")
With ThisWorkbook
For Each File In Fso.GetFolder(p).Files
If File.Name Like "*.xls" Then
n = n + 1
Set Wb = Workbooks.Open(File)
Application.DisplayAlerts = False
If ThisWorkbook.MultiUserEditing Then
ThisWorkbook.UnprotectSharing ("")
End If
Application.DisplayAlerts = True
Wb.Unprotect
Wb.Sheets("基本情况(填表)").Unprotect
Wb.Sheets("基本情况(填表)").Rows("1:4").delete
Wb.Close False
End If
Next
End With
Set Fso = Nothing
Application.ScreenUpdating = True
MsgBox "表头已删除!"
End Sub
补充内容(2015-7-30 15:33:13):
我的个性签名