在Excel中使用命令按钮创建一个新的TextFile. [英] Create a new TextFile With command button in excel.
本文介绍了在Excel中使用命令按钮创建一个新的TextFile.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在excel中使用命令按钮创建一个新的TextFile.
我已添加此代码
Create a new TextFile With command button in excel.
I have added this code
Public Sub PopulateTextFile()
Dim fso As New FileSystemObject
Dim oFile As TextStream
If (Not fso.FileExists("C:\Test.txt")) Then
Set oFile = fso.CreateTextFile("C:\Test.txt", False)
End If
oFile.WriteLine "Test"
oFile.Close
Set oFile = Nothing
Set fso = Nothing
End Sub
但显示错误:未在fso中定义的用户定义类型
请提出任何建议....
But It Is Showing Error:User Defined Type Not Defined at fso
Please give any suggestions....
推荐答案
很抱歉给您带来麻烦....
我对此有解决方案,因为我必须添加
参考 MicrosoftScriptingRuntime
Sorry for troubling you people....
I got solution for this,as i have to add reference as
MicrosoftScriptingRuntime
您的代码无法检测到FileSystemObject.确保此脚本编制组件已在您的PC上正确注册.
另外,在VBE中.转到工具->引用并检查Microsoft Scripting Runtime
是否已添加.
Your code is not able to detect FileSystemObject. Make sure this scripting component is correctly registered on your PC.
Also, in VBE. goto Tools -> References and checkMicrosoft Scripting Runtime
is added.
这篇关于在Excel中使用命令按钮创建一个新的TextFile.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文