gpt4 book ai didi

Excel VBA : Run Time Error 1004 : Excel cannot access to file

转载 作者:行者123 更新时间:2023-12-04 22:30:33 27 4
gpt4 key购买 nike

我正在创建报告生成器的宏,让用户可以将文件的副本保存到其目的地。

单元格值(“E5”)是用户输入日期的位置。
单元格值(“E11”)是用户键入记录名称的位置(在本例中为颜色值)

宏会将其保存到C盘中的位置

这是代码:

Sub CTemplate()

'Select up the macro generator
Sheets("File Generator").Select

'Save file according to the textbox values

Dim filename As String
Dim varDatevalue As String
Dim varColourvalue As String

varDatevalue = Range("E5").Value
varColourvalue = Range("E11").Value

ActiveWorkbook.SaveAs filename:="C:\Colour Log\" & varDatevalue & "--" & varColourvalue & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

但是,当我遇到运行时错误时存在一些问题:
enter image description here

我已经尝试如下:
  • 调试并搜索 SO 但找不到其他有相同问题的人
  • 我已经在所需位置创建了文件夹
  • 取消选中(“只读”)文件的复选框,以便可以写入

  • 谢谢你 。

    最佳答案

    “文件名不能包含以下任何字符:\/: * ?” < > |” - 您的文件名似乎是“5\11\4192C700”,这实际上意味着您正在尝试将文件保存在非现有目录 c:\Colour Log\5\11\4192C700. 您必须将文件名中的斜杠更改为其他字符。

    关于Excel VBA : Run Time Error 1004 : Excel cannot access to file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53147490/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com