我正在为名为“ScorBase”的程序编写 VBA 脚本。我正在尝试调用一个创建文本文件的子程序,但我遇到了这个错误“506”。
这是我正在写的代码:
Sub emailFile()
' Declare a TextStream.
Dim stream
'As TextStream
dim fso
Set fso = New FileSystemObject
' Create a TextStream.
Set stream = fso.CreateTextFile("C:\Users\eladt\Desktop\creatFile\Mail.txt", True)
stream.WriteLine "user Email."
stream.WriteLine "Maki"
stream.WriteLine "Nigeri"
stream.WriteLine "Sashimi"
stream.Close
End Sub
最佳答案
不使用任何外部引用的更简单的方法:
Sub MM_Email_To_File()
Dim FF As Integer
FF = FreeFile
'// The file will be created if it doesn't exist
Open "C:\Users\eladt\Desktop\creatFile\Mail.txt" For Output As #FF
Print #FF, "User Email"
Print #FF, "Maki"
Print #FF, "Nigeri"
Print #FF, "Sashimi"
Close #FF
End Sub
您可以查看 this MSDN article 以获取有关 VBA 中 I/O 操作的更多信息。
关于vba - 错误 506 : Class not defined: 'FileSystemObject' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36280510/