无法在 macOS 中使用 VBA(MS Word for Mac)创建带有西里尔字符的文件名。

huangapple go评论72阅读模式
英文:

Cannot create a file if filename has Cyrillic characters in macOS with VBA (MS Word for Mac)

问题

Here's the translated content without the code parts:

刚刚从PC切换到Mac,正在准备好一切,包括我的旧VBA程序。
问题是,我无法创建一个文件名包含一些西里尔字符的文本文件。

自从我从Windows切换到Mac后,这个VBA代码(MS Word)不再起作用:
我收到了一个Visual Basic运行时错误 '75':“路径/文件访问错误”。

如果我这样说,它就可以正常工作:
有没有办法解决这个问题?不幸的是,我已经了解到,文件系统对象只支持Windows,而我使用的是macOS(默认语言=俄语)。因此,我不知道除了使用“打开”语句之外,还有什么方法可以创建文本文件。

我还尝试将StrConv函数应用于文件名,但也没有帮助。

英文:

Just recently moved from PC to Mac and getting the things ready, including my old VBA programs.
The issue is that I cannot create a text file which filename has some Cyrillic characters.

This VBA code (MS Word) does not work anymore since I moved from Windows to Mac:

Dim fname As String
fname = db_path + "кириллица-test123.txt"
Close #1

Open fname For Output As #1
Print #1, "Hello!"
Print #1, "Привет!"
Close #1

I have got a Visual Basic Run-time error '75': "Path/File access error".

It works fine though, if I say:

frame = db_path + "test.123.txt"

Any idea how to sort it out? Unfortunately, as I have learned already, File System Objects are only supported on Windows and I am on macOS (default language = Russian). Thus I do not know any way to create text file rather than use the "Open" statement.

I tried also to apply StrConv function to the filename but it did not help either.

答案1

得分: 1

Can't provide a solution to this right now, but...

主要问题似乎是在 Mac 上,旧的内置 VBA 文件命令只识别 8 位字符代码。

我不能确定没有重新配置我的 Mac,这会如何影响那些使用 Cyrillic 脚本语言的人。

在这里(在英语设置上),它会影响我在 VB 编辑器中看到的内容(即所有 Cyrillic 字符都显示为“?”)。这是预期的。

但是,如果我将您的文件名更改为一个单一的 Cyrillic-Њ 字符,可以使用以下代码:

fname = db_path + Chr(&H400) & "-test123.txt"

我会收到“无效的过程调用或参数”错误。

但是,如果我使用 2 字节的 UTF8 等效值 &H400,如下所示:

fname = db_path + Chr(208) & Chr(138) & "-test124.txt"

...会创建一个以 &H400 字符开头的文件,正如您希望的那样。

此外,使用 Chr(208) & Chr(138) 将相同的字符写入文件似乎有效。

没有坚实的解决方案,但也许值得探索,因为我现在要离开几天。

英文:

Can't provide a solution to this right now, but...

The main problem here seems to be that on Mac, the old built-in VBA File commands only recognise 8 bit character codes.

What I can't tell without a lot of reconfiguration of my Mac is exactly how that affects someone who has a Mac set up for a Cyrillic script language.

Here (on an English language set-up) it affects what I see in the VB Editor (i.e. all the Cyrillic characters appear as "?"). That's expected.

But let's say I change your file name to a single Cyrillic-Њ character using this:

fname = db_path +  Chr(&H400)  & "-test123.txt"

I get an "invalid procedure call or argument" error.

But if I use the 2-byte UTF8 equivalent of &H400, like this...

fname = db_path + Chr(208) & Chr(138) & "-test124.txt"

...a file is created with a name starting with the &H400 character as you might hope.

further, using Chr(208) & Chr(138) to write the same character to the file seems to work.

No solid ground for a solution there, but perhaps something to explore as I am away for a few days now.

huangapple
  • 本文由 发表于 2023年5月13日 21:38:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243015.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定