我有一个sub,我打电话来保存文件
Sub SaveToFile()
maxr = Worksheets("List").Range("H1")
Worksheets("List").Range("G1:AE" & maxr).Copy
升级到2007之后失败的部分代码是:
With Application.FileSearch
.LookIn = "Q:\Planning Tools\Reports\"
.Filename = "Plan_" & ThisSaveTime & ".xls"
我收到运行时错误'445'对象不支持此操作,代码接下来继续:
If .Execute > 0 Then 'Existing Workbook
Application.Workbooks.Open ("Q:\Planning Tools\Reports\Plan_" & ThisSaveTime & ".xls")
ActiveWorkbook.Worksheets.Add
ActiveWorkbook.Sheets("Sheet1").Select
ActiveWorkbook.Sheets("Sheet1").Name = ThisPlanSaveName
Else 'No existing Workbook, so add one
Workbooks.Add 1
ActiveWorkbook.Sheets("Sheet1").Select
ActiveWorkbook.Sheets("Sheet1").Name = ThisPlanSaveName
End If
End With
......
End Sub
我不确定哪个动作失败但有人能看出原因吗?
由于
答案 0 :(得分:3)
Microsoft已从Excel 2007对象模型中删除 FileSearch
有许多可能的替代品,例如 Dir 并使用 FileSystemObject
试试这些链接: