另存为语法和range.select索引语法?

发布于 2024-11-30 19:50:40 字数 345 浏览 1 评论 0原文

我正在尝试编写一些代码行来选择 Excel 中的范围,但该范围的索引有语法错误,有什么建议吗?另外,我试图将 XML 文件另存为 xlsm 文件,其文件名来自存储在数组中的两个文件名的串联,并且出现类似的错误。有什么建议吗?

        Range (Allfiles(index)).select 'Allfiles is an array containing the file names ' type error


        Activeworkbooks.saveas "c:\Allfiles(1):&:Allfiles (count).xlsm", fileformat=52 'error

I'm trying to write some lines of codes that select a range in excel but the index to the range has a syntax error any suggestions? Also I'm trying to save a XML file as an xlsm file with file names from the concactenation of two file names stored in an array and is getting a similar error.any suggestions??

        Range (Allfiles(index)).select 'Allfiles is an array containing the file names ' type error


        Activeworkbooks.saveas "c:\Allfiles(1):&:Allfiles (count).xlsm", fileformat=52 'error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾兮 2024-12-07 19:50:40

当您收到“错误”时,有用的“错误消息”将提示您问题所在。通过阅读此消息并对其采取行动,您可以逐步调试代码。

Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat = 52
'                                           Variable not defined ^

在 VBA 中指定参数的方法是使用 :=,而不是 =。让我们更正该问题并再次运行它...

Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
' ^ Variable not defined

它的名称为 ActiveWorkbook,而不是 Activeworkbooks。让我们更正这个问题并再次运行它...

ActiveWorkbook.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
'                                     ^ The file could not be accessed.

我不能声称确切地知道您正在运行什么操作系统,但考虑到 C:\,我会假设 Windows 的某种风格。您可能知道 : 在 Windows 路径中是非法字符?

无论如何,我不确定您要将此文件保存在哪里。我最好的猜测:

ActiveWorkbook.SaveAs "C:\" & Allfiles(1) & Allfiles(UBound(Allfiles)) & ".xlsm", _
    FileFormat:=52

至于你的第一行代码,Range (Allfiles(index)).Select,我不知道你想在那里做什么。您可能需要阅读 Excel-VBA 的帮助文件以了解 Range 的作用。

When you get an "error", a useful "error message" will give you a hint as to what the problem is. By reading this message and acting upon it, you can debug your code step by step.

Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat = 52
'                                           Variable not defined ^

The way to specify arguments in VBA is with :=, not =. Let's correct that and run it again...

Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
' ^ Variable not defined

It's called ActiveWorkbook, not Activeworkbooks. Let's correct that and run it once more...

ActiveWorkbook.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
'                                     ^ The file could not be accessed.

I can't claim to know for sure what OS you're running, but given the C:\, I'll assume some flavour of Windows. You may know that : is an illegal character in paths in Windows?

Anyhow, I'm not sure where you're trying to save this file. My best guess:

ActiveWorkbook.SaveAs "C:\" & Allfiles(1) & Allfiles(UBound(Allfiles)) & ".xlsm", _
    FileFormat:=52

As for you first line of code, Range (Allfiles(index)).Select, I have no clue what you're trying to do there. You may want to read Excel-VBA's help file to learn what Range does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文