尝试在映射服务器上将XLSM保存为CSV时,“对象_workbook的方法保存失败”错误

时间:2017-12-01 21:33:08

标签: vba excel-vba csv methods save-as

您好,我试图将xlsm文件保存为我映射到计算机上的服务器上的CSV。
这里是代码:

CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
' Store current details for the workbook
SaveToDirectory = "Y:\"
    ActiveWorkbook.SaveAs Filename:=SaveToDirectory & "Project_Type_Test" & ".csv", FileFormat:=xlCSV
    ActiveWorkbook.Close savechanges:=False
    ThisWorkbook.Activate

VBA表示该错误来自这行代码:

         
ActiveWorkbook.SaveAs Filename:=SaveToDirectory & "Project_Type_Test" & ".csv", FileFormat:=xlCSV

我试图通过ThisWorkbook切换ActiveWorkbook,但它没有改变任何内容。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我运行了代码,如果我将它设置为我的硬盘,它对我来说很好。

Sub tst()Possibly try using the url instead of the mapped dive letter

CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
' Store current details for the workbook
SaveToDirectory = "C:\TEMP\" 'CHANGED THIS TO BE MY HD AND WORKS FINE
ActiveWorkbook.SaveAs Filename:=SaveToDirectory & "Project_Type_Test" & ".csv", FileFormat:=xlCSV
ActiveWorkbook.Close savechanges:=False
ThisWorkbook.Activate
End Sub

可能尝试使用资源的url而不是映射的驱动器号

  • “\\ machine \ path \”
  • 而不是“Y:\”