我有一个从选项卡输出信息的小宏,但是它没有保存输出的文本文件。当它运行调试时它突出显示一行,但我看不出它有什么问题。
这是调试中的错误行:
ActiveWorkbook.SaveAs Filename:=pathname, FileFormat:= _
xlTextMSDOS, CreateBackup:=False
错误讯息:
方法' SaveAs'对象' _Workbook'失败
这是整个代码
Sub Savetxt(pathname, sheetname)
Sheets("Output").Range("A1:Z99999").ClearContents
Sheets(sheetname).Select
Range(ActiveSheet.ListObjects(1) & "[Final output for text file]").Copy
Sheets("Output").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Rows("1:1").Select
'Application.CutCopyMode = False
'Selection.Delete Shift:=xlUp
BName = ActiveWorkbook.FullName
ActiveWorkbook.VBProject.VBComponents("module1").Export ("' & BName.Value &'")
Sheets(Array("Output")).Copy
Application.VBE.ActiveVBProject.VBComponents.Import ("' & BName.Value &'")
ActiveWorkbook.SaveAs Filename:=pathname, FileFormat:= _
xlTextMSDOS, CreateBackup:=False
' ActiveWorkbook.SaveAs Filename:=Range("savefile").Value _
, FileFormat:=xlTextMSDOS, CreateBackup:=False
'
ActiveWindow.Close
End Sub
答案 0 :(得分:1)
pathname
,因此它试图将文档保存在不存在的位置。