NewBook.SaveAs命中'1004'运行时错误 [英] NewBook.SaveAs hitting '1004' Runtime Error

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

问题描述

我有这个代码适用于旧版本的Excel。但是在Excel 2016上使用它时,我一直遇到'1004'运行时错误,说路径不可访问或文件名中有特殊字符。

I have this code which worked on older version of Excel. But upon using it on Excel 2016, I kept hitting '1004' runtime error, saying that either the path is not accessible or there are special characters in the filename.

我创建了一个msbox到显示FileName1并显示"C:\ Runbooka.xlsx"

I created a msbox to display FileName1 and it shows "C:\Runbooka.xlsx"

我的代码如下:

         FileName1 = Worksheets(&#; Sheet1")。Cells(8,8).Value

        MsgBox FileName1

        ActiveWorkbook.Save

        Newbook.SaveAs FileName:= FileName1,_

        FileFormat:= xlOpenXMLWorkbook,CreateBackup:= False

        FileName1 = Worksheets("#Sheet1").Cells(8, 8).Value
        MsgBox FileName1
        ActiveWorkbook.Save
        Newbook.SaveAs FileName:=FileName1, _
        FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

如果我将'Newbook.SaveAs FileName:= FileName1,_'替换为',则上述方法有效Newbook.SaveAs FileName:=" C:\ Runbooka.xlsx",_'

The above works if I replace 'Newbook.SaveAs FileName:=FileName1, _' with 'Newbook.SaveAs FileName:="C:\Runbooka.xlsx", _'

有没有办法使用像FileName1这样的变量来保存?

Is there a way to saveas using a variable like FileName1?

谢谢!

推荐答案

这是在VB.NET项目中还是这个VBA代码还是VB6?

Is this in a VB.NET project or is this VBA code or VB6?

如果这不是VB.NET,上面的问题将帮助我将你的问题转移到正确的论坛。如果VB.NET我们需要更多的细节(但是怀疑这是你使用MsgBox的格式的VB.NET)。

If this is not VB.NET the above question will assist me in moving your question to the right forum. If VB.NET we need more details (yet doubt this is VB.NET from the format of how you use MsgBox).


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

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