100分求助:vba 调用模块问题
我在excel中想编点代码,实习写文件功能,在一个按钮的事件中调用写文件模块中的一个函数,不知道为什么老提示,"编译错误:要求对象",哪位仁兄能帮帮忙,告诉我为什么呀?要有实现代码能贴出来那就太感谢啦. --------------------编程问答-------------------- 其实把自己的相关的那部分代码贴出来,别人还容易给你解决问题点. --------------------编程问答-------------------- 谢谢提醒,现将代码贴出:模块一中的代码:
'将字符串写入文件
Public Function writeStringToFile(sTargetString As String, sFileName As String) As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set fs_jb = fs.CreateTextFile(filepathname, True)
fs_jb.writeline (sTargetString)
fs_jb.Close
writeFile = "写入文件成功!"
End Function
按钮事件中的代码:
Private Sub CommandButton_getTbsDefine_Click()
Set sRtn = writeStringToFile("aaaa", "d:\test.sql")
MsgBox sRtn, vbInformation, "提示"
End Sub
--------------------编程问答-------------------- 先解决你的“要求对象”的问题:
修改你的代码:
--------------------编程问答-------------------- 第二个:你的Function中有个“变量”可能有误!
'按钮事件中的代码:
Private Sub CommandButton_getTbsDefine_Click()
Dim sRtn$
sRtn = writeStringToFile("aaaa", "d:\test.sql")
MsgBox sRtn, vbInformation, "提示"
End Sub
Set fs_jb = fs.CreateTextFile(filepathname, True)
这里面的:filepathname 与参数中的: sFileName 不一样,不知道是不是LZ写错了。 --------------------编程问答-------------------- 测试
VBScript code
Set fs_jb = fs.CreateTextFile(filepathname, True) --------------------编程问答--------------------
再测试
VBScript codeSet
fs_jb = fs.CreateTextFile(filepathname, True)
--------------------编程问答-------------------- 测试3
第二个:你的Function中有个“变量”可能有误!
VBScript codeSet fs_jb = fs.CreateTextFile(filepathname, True)
这里面的:filepathname 与参数中的: sFileName 不一样,不知道是不是LZ写错了。 --------------------编程问答-------------------- 测试4
fs_jb = fs.CreateTextFile(filepathname, True)
--------------------编程问答--------------------
Set fs_jb = fs.CreateTextFile(filepathname, True)
--------------------编程问答--------------------
--------------------编程问答-------------------- 终于会了 --------------------编程问答-------------------- 什么呀
SET fs_jb = fs.CreateTextFile(filepathname, True)
补充:VB , VBA