Cannot save file after upgrade to 2007 VBA

2019-08-31 00:21发布

I have a sub which I call to save a file

Sub SaveToFile()

    maxr = Worksheets("List").Range("H1")

    Worksheets("List").Range("G1:AE" & maxr).Copy

Part of the code which is failing after an upgrade to 2007 is:

    With Application.FileSearch
        .LookIn = "Q:\Planning Tools\Reports\"
        .Filename = "Plan_" & ThisSaveTime & ".xls"

I receive a runtime error '445' object doesn't support this action, the code then continues below:

        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

I am not sure which action is failing but can anyone see why?

Thanks

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-31 00:38
登录 后发表回答