I have this code that allows the user to open a file using 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
when I'm trying to change Sheets("Main").txtSrc.Value = sFileName
to ws.txtSrc.Value = sFileName
, it returns the method or data member not found error. By the way, txtSrc
is an ActiveX Control textbox. Can someone help me understand this?
The Worksheet
class does not have a txtSrc
property. Declare the ws
variable as Object
or as the specific sheet interface (its code name).
ws.Shapes("txtSrc").OLEFormat.Object.object.value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.