运行时错误1004文档未保存 [英] Runtime error 1004 Document Not Saved

查看:334
本文介绍了运行时错误1004文档未保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Excel 2010中写了一个宏。

我想用下面的代码保存excel文件

应用程序.Workbooks(Dir(reportName))。SaveAs

这里报告名称是文件的强制路径​​


但是获取运行时错误1004文档未保存。


请帮忙。

Hi,
I have written one macro in excel 2010.
I am trying to save the excel file using below code
Application.Workbooks(Dir(reportName)).SaveAs
Here report name is the compelte path of the file

But getting runtime error 1004 Document Not Saved.

Please help.

推荐答案

我认为你的语法略有错误。根据帮助,语法为:
expression.SaveAs(FileName,...)


其中表达式标识要保存的工作簿(而不是要保存的文件)。猜测,与 Dir()的业务看起来好像可能属于 FileName 参数。
I think you have the syntax slightly wrong. According to the help, the syntax is:
expression.SaveAs(FileName,...)

Where expression identifies the workbook you want to save (not the file to save it in). At a guess, that business with Dir() looks as though it probably belongs in the FileName parameter.


你在错误的论坛。你的主题已被移动到Excel论坛。


同样根据Killer42的说法。但是,您还需要找到工作簿的正确索引。如果那是唯一打开的工作簿,则很可能是0。
You are in the wrong forum. Your thread has been moved to the Excel forum.

Ditto on what Killer42 said. But also, you will need to find the correct index for the Workbook. Most likely 0 if that''s the only workbook open.


表达式是Excel的对象。

例如Excel.Application

但是我没有创建对象而是我正在尝试

Application.Workbooks(Dir(reportName))。保存



目的使用Dir(reportname)是因为打开了多个excel文件而不是提供整个路径只是使用Dir传递excel的名称


我是试图多次保存excel。

第三次失败后。
Expression is the object of Excel.
For e.g. Excel.Application
But I am not creating object instead I am trying
Application.Workbooks(Dir(reportName)).Save


Purpose to use Dir(reportname) is since there are multiple excel files opened so rather than providing entire path just passing the name of the excel using Dir

I am trying to save the excel multiple times.
After 3rd it fails.


这篇关于运行时错误1004文档未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆