我有这段代码,允许用户使用filepicker打开文件
Sub SelectFile()
Dim sFileName As Variant
Dim ws As Worksheet
Set ws = Sheets("Main")
sFileName = Application.GetOpenFilename("MS Excel (*.csv), *.xlxs")
If sFileName = False Then
MsgBox "No file selected.", vbInformation, "Warning!"
Exit Sub
End If
Sheets("Main").txtSrc.Value = sFileName
End Sub
当我尝试将Sheets("Main").txtSrc.Value = sFileName
更改为ws.txtSrc.Value = sFileName
时,它会返回找不到方法或数据成员的错误。顺便说一下,txtSrc
是一个ActiveX控件文本框。有人能帮助我理解这个吗?
答案 0 :(得分:2)
Worksheet
类没有txtSrc
属性。将ws
变量声明为Object
或声明为特定表单界面(其代码名称)。
答案 1 :(得分:0)
ws.Shapes("txtSrc").OLEFormat.Object.object.value