尝试保存XLSM文件时,对象_workbook的方法saveas失败“错误

时间:2015-06-08 05:41:50

标签: excel excel-vba vba

我有一个主工作簿'WORK ORDER.xlsm'。有几个工作表(主要,摘要14天,发票,数据)。我的员工每天填写“摘要14天”表,最后按下vba代码按钮。我的目的是保存具有不同名称和实际发票号的工作簿(总是相同的公司网络文件夹),清除“摘要14天”表并增加发票号。 有时,但并非总是如此,它失败并且出现错误消息(运行时错误1004:对象_workbook的方法saveas失败)弹出,调试器将我指向此行:

ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook

运行代码至少需要2分钟。任何建议如何改进此代码。我正在使用Office 2011 for Mac和所有员工Office 365 for Windows)。提前谢谢。

Sub NextInvoice()
Range("'Summary 14 days'!Q3").Value = Range("'Summary 14 days'!Q3").Value + 1
Range("'Summary 14 days'!C9:'Summary 14 days'!G16").ClearContents
Range("'Summary 14 days'!B59:'Summary 14 days'!B66").ClearContents
Range("'Summary 14 days'!B101:'Summary 14 days'!B106").ClearContents
Range("'Summary 14 days'!B127:'Summary 14 days'!B134").ClearContents
Range("'Summary 14 days'!B139:'Summary 14 days'!B146").ClearContents
Range("'Summary 14 days'!B153:'Summary 14 days'!B154").ClearContents
Range("'Summary 14 days'!D21:'Summary 14 days'!Q23").ClearContents
Range("'Summary 14 days'!D25:'Summary 14 days'!Q25").ClearContents
Range("'Summary 14 days'!D27:'Summary 14 days'!Q27").ClearContents
Range("'Summary 14 days'!D29:'Summary 14 days'!Q29").ClearContents
Range("'Summary 14 days'!D31:'Summary 14 days'!Q31").ClearContents
Range("'Summary 14 days'!D33:'Summary 14 days'!Q33").ClearContents
Range("'Summary 14 days'!D35:'Summary 14 days'!Q35").ClearContents
Range("'Summary 14 days'!D37:'Summary 14 days'!Q37").ClearContents
Range("'Summary 14 days'!D39:'Summary 14 days'!Q39").ClearContents
Range("'Summary 14 days'!D41:'Summary 14 days'!Q41").ClearContents
Range("'Summary 14 days'!D43:'Summary 14 days'!Q43").ClearContents
Range("'Summary 14 days'!D45:'Summary 14 days'!Q45").ClearContents
Range("'Summary 14 days'!D47:'Summary 14 days'!Q47").ClearContents
Range("'Summary 14 days'!D49:'Summary 14 days'!Q49").ClearContents
Range("'Summary 14 days'!D51:'Summary 14 days'!Q51").ClearContents
Range("'Summary 14 days'!D53:'Summary 14 days'!Q53").ClearContents
Range("'Summary 14 days'!D55:'Summary 14 days'!Q55").ClearContents
Range("'Summary 14 days'!D57:'Summary 14 days'!Q57").ClearContents
Range("'Summary 14 days'!D59:'Summary 14 days'!Q59").ClearContents
Range("'Summary 14 days'!D61:'Summary 14 days'!Q61").ClearContents
Range("'Summary 14 days'!D63:'Summary 14 days'!Q63").ClearContents
Range("'Summary 14 days'!D65:'Summary 14 days'!Q65").ClearContents
Range("'Summary 14 days'!D71:'Summary 14 days'!Q71").ClearContents
Range("'Summary 14 days'!D73:'Summary 14 days'!Q73").ClearContents
Range("'Summary 14 days'!D75:'Summary 14 days'!Q75").ClearContents
Range("'Summary 14 days'!D77:'Summary 14 days'!Q77").ClearContents
Range("'Summary 14 days'!D79:'Summary 14 days'!Q79").ClearContents
Range("'Summary 14 days'!D81:'Summary 14 days'!Q81").ClearContents
Range("'Summary 14 days'!D83:'Summary 14 days'!Q83").ClearContents
Range("'Summary 14 days'!D85:'Summary 14 days'!Q85").ClearContents
Range("'Summary 14 days'!D87:'Summary 14 days'!Q87").ClearContents
Range("'Summary 14 days'!D89:'Summary 14 days'!Q89").ClearContents
Range("'Summary 14 days'!D91:'Summary 14 days'!Q91").ClearContents
Range("'Summary 14 days'!D93:'Summary 14 days'!Q93").ClearContents
Range("'Summary 14 days'!D95:'Summary 14 days'!Q95").ClearContents
Range("'Summary 14 days'!D97:'Summary 14 days'!Q97").ClearContents
Range("'Summary 14 days'!D99:'Summary 14 days'!Q99").ClearContents
Range("'Summary 14 days'!D101:'Summary 14 days'!Q101").ClearContents
Range("'Summary 14 days'!D103:'Summary 14 days'!Q103").ClearContents
Range("'Summary 14 days'!D105:'Summary 14 days'!Q105").ClearContents
Range("'Summary 14 days'!D111:'Summary 14 days'!Q111").ClearContents
Range("'Summary 14 days'!D113:'Summary 14 days'!Q113").ClearContents
Range("'Summary 14 days'!D115:'Summary 14 days'!Q115").ClearContents
Range("'Summary 14 days'!D117:'Summary 14 days'!Q117").ClearContents
Range("'Summary 14 days'!D119:'Summary 14 days'!Q119").ClearContents
Range("'Summary 14 days'!D121:'Summary 14 days'!Q121").ClearContents
Range("'Summary 14 days'!D123:'Summary 14 days'!Q123").ClearContents
Range("'Summary 14 days'!D125:'Summary 14 days'!Q125").ClearContents
Range("'Summary 14 days'!D127:'Summary 14 days'!Q127").ClearContents
Range("'Summary 14 days'!D129:'Summary 14 days'!Q129").ClearContents
Range("'Summary 14 days'!D131:'Summary 14 days'!Q131").ClearContents
Range("'Summary 14 days'!D133:'Summary 14 days'!Q133").ClearContents
Range("'Summary 14 days'!D139:'Summary 14 days'!Q139").ClearContents
Range("'Summary 14 days'!D141:'Summary 14 days'!Q141").ClearContents
Range("'Summary 14 days'!D143:'Summary 14 days'!Q143").ClearContents
Range("'Summary 14 days'!D145:'Summary 14 days'!Q145").ClearContents
Range("'Summary 14 days'!D151:'Summary 14 days'!Q151").ClearContents
Range("'Summary 14 days'!D153:'Summary 14 days'!Q153").ClearContents
Range("'Summary 14 days'!C175:'Summary 14 days'!Q202").ClearContents
End Sub

Sub SaveInvoice()
Dim NewFN As Variant
ActiveWorkbook.Sheets.Copy
NewFN = " N:\Network\WORK ORDERS\WR" & Range("'Summary 14 days'!Q3").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
Workbooks("WORK ORDER.xlsm").Save
Workbooks("WORK ORDER.xlsm").Close
End Sub

0 个答案:

没有答案