VBA另存为特殊字符错误 [英] VBA Save As special character error

查看:133
本文介绍了VBA另存为特殊字符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码运行完美.为了进行内部报告跟踪,我在文件名的前面附加了"[1944]".现在它正在向我退还运行时错误'1004'".

This code below was running perfect. For internal report tracking purposes I've appended "[1944] " to the front of the file name. It's now kicking back "Run-time error '1004'" at me.

错误1004清单

  • 文件夹存在
  • 文件不是只读的
  • Len(文件路径)<218

上一节中的引用未使用以下字符<>?[]:|或*

Last section references not using the following characters < > ? [ ] : | or *

但是,如果我转到文件夹位置,则可以使用[]重命名它,没问题.我什至可以为此文件加上标题并使用VBA启动它那么,为什么不能保存其中的文件.

But if I go to the folder location I can rename it using [ ] no problem. I can even title a file with this and launch it using VBA So why can't I save a file with it in.

有人为我工作吗?

非常感谢!

ActiveWorkbook.SaveAs Filename:= _
    strfilepath & "[1944] TSA34_MI_" & strdt & ".xlsb" _
    , FileFormat:=xlExcel12, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False

推荐答案

我能想到的唯一解决方法是在文件关闭后重命名.

The only workaround I can think of is renaming the file once it is closed.

为此,您可以使用 Name 语句.请参见 MSDN文档.

To do this you can use the Name statement. See MSDN documentation.

Name "C:\Users\lturner\Documents\myWorkbook.xlsb" As "C:\Users\lturner\Documents\[1]myWorkbook.xlsb"

除此之外,我认为不可能将工作簿的名称保存在方括号中.

Aside from this, I don't think it's possible to save the workbook with square brackets in the name.

这篇关于VBA另存为特殊字符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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