我在其他2个文件中的下面的代码工作正常,但由于某种原因,我在运行时得到了这个SaveAs的ojbect错误。更奇怪的是,如果我调试并再次点击运行它完成没有错误。
Sub saveWorksheet()
Set report = ActiveWorkbook.Worksheets("Report")
sb_Copy_Save_Worksheet_As_Workbook
End Sub
Sub sb_Copy_Save_Worksheet_As_Workbook()
Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Report").Copy Before:=wb.Sheets(1)
wb.Sheets(1).Name = Day(Now) & "-" & MonthName(Month(Now), True) & "-" &
Year(Now) & " " & getTime
Application.DisplayAlerts = False
wb.Sheets("Sheet1").Delete
wb.SaveAs "\\Naeast.ad.jpmorganchase.com\amerawm$\AM\NAAMSHARE13\AM
Oversight and control\DE Program Team\User Tools\14. Daily
Trackers\Compliance Check Archive\" & Month(Date) & "-" & Day(Date) & "-"
& Year(Date) & "-" & "New_Compliance_Check.xlsx"
wb.Close
Application.DisplayAlerts = True
End Sub
Function getTime()
If Len(Time) = 10 Then
getTime = Left(Time, 1) & "." & Mid(Time, 3, 2)
Else
getTime = Left(Time, 2) & "." & Mid(Time, 4, 2)
End If
End Function
突出显示的调试行是:
wb.SaveAs "\\Naeast.ad.jpmorganchase.com\amerawm$\AM\NAAMSHARE13\AM Oversight and control\DE Program Team\User Tools\14. Daily Trackers\Compliance Check Archive\" & Month(Date) & "-" & Day(Date) & "-" & Year(Date) & "-" & "New_Compliance_Check.xlsx"
编辑:我根据你的建议更新了代码,但同样的问题。
wb.Sheets("Sheet1").Delete
wb.Activate
wb.SaveAs "\\Naeast.ad.jpmorganchase.com\amerawm$\AM\NAAMSHARE13\AM
Oversight and control\DE Program Team\User Tools\14. Daily
Trackers\Compliance Check Archive\" & Month(Date) & "-" & Day(Date) & "-" &
Year(Date) & "-" & "New_Compliance_Check.xlsx"
wb.Close
我之前遇到过类似的情况,Excel似乎对我所指的工作簿感到困惑。在wb.Activate
之前尝试wb.SaveAs
另外(不确定这是否适用于您)但是当保存到Sharepoint时,我不得不在文件路径中将所有\
反转为/
。