我正在尝试打开工作簿并从中删除工作表,但它运行代码没有错误,工作表仍然存在......我可以修改它,因为我将公式更改为另一张工作表上的值。首先 - 是的,我知道“i”变量设置为进行 1 次迭代。不知何故,现在当我打开工作簿时,它说它被我锁定了——我什至不知道该怎么做。
那么……我该如何解锁呢?当我转到文件-->信息-->权限时,它说'任何人都可以复制、更改和修改此工作簿的任何部分......我也可以手动删除工作表......
这是代码:
Sub Change()
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
Dim ws As Excel.Worksheet
Set ws = wb.Sheets("FileSearch Results")
Dim rng As Range
Set rng = ws.UsedRange
Dim cPaths As Integer
cPaths = rng.Column
Dim i As Integer
i = rng.Row
Dim oExcel As Excel.Application
Set oExcel = New Excel.Application
Dim oWB As Workbook
Dim komm As Excel.Worksheet
Dim sh1 As Excel.Worksheet
Do While i < 2
Dim pth As String
pth = ws.Cells(i, cPaths)
Set oWB = oExcel.Workbooks.Open(pth)
Set sh1 = oWB.Worksheets("Sheet1")
With sh1.UsedRange
.Value = .Value
End With
Set komm = oWB.Worksheets("Kommentar")
Application.DisplayAlerts = False
komm.Delete
Application.DisplayAlerts = True
oWB.Close savechanges:=True
i = i + 1
Loop
End Sub
有任何想法吗?