excel的VB5.8中编程哪里有错
思路:搜索电脑F盘内全部.xls文件,搜索到立即打开,如果发现有名称为00000ppy的隐藏工作表(位置是格式-工作表-取消隐藏),则删除此表。然后删除插入-名称-定义中所有定义项目,保存工作表,关闭,继续循环到全部项目完成。
我改编了一个,懂的可以看看。使用起来没错,但无法删除那些我要删的内容,望高手指导。
Dim fs
Dim mypath As String
Dim theSh As Object
Dim theFolder As Object
Set theSh = CreateObject("shell.application")
Set theFolder = theSh.BrowseForFolder(0, "", 0, "")
If Not theFolder Is Nothing Then
mypath = theFolder.Items.Item.Path
End If
Set fs = Application.FileSearch
With fs
.NewSearch
.SearchSubFolders = True
.LookIn = mypath
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName) > 0 Then
c = .FoundFiles.Count
Application.ScreenUpdating = False
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
On Error Resume Next
For i = 1 To c
Workbooks.Open Filename:=.FoundFiles(i)
Sheets("00000ppy").Visible = -1
Sheets("00000ppy").Delete
ActiveWorkbook.Names("solar_ratio").Delete
ActiveWorkbook.Names("ss7fee").Delete
ActiveWorkbook.Names("subsfee").Delete
ActiveWorkbook.Names("toolbox").Delete
ActiveWorkbook.Names("Z32_Cost_red").Delete
ActiveWorkbook.Names("V5.1Fee").Delete
ActiveWorkbook.Save
ActiveWorkbook.Close
Next
End If
End With
Set fs = Nothing
Application.ScreenUpdating = True
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True
End Sub
用的是excel打开后按ALT+F11。
用途是反制一个宏。