我有以下代码:
Dim Op1 As String
Dim Op2 As String
Dim operatore As String
operatore = ComboBox1.Value
Op1 = operatore.Substring(0, operatore.IndexOf("<")).Trim()
Op2 = operatore.Split(">")(1)当我编译时,我得到一个错误:“限定符无效”引用到变量"operatore“。我怎么才能修复它?
发布于 2018-01-20 01:27:02
如果您关注的是VBA,而不是VB.Net,那么您需要使用Split()来引用拆分的阵列,使用OLEObjects()来引用OLEObjects。
这将编译并返回您可能需要的内容:
Option Explicit
Sub TestMe()
Dim Op1 As String
Dim Op2 As String
Dim operatore As String
operatore = ActiveSheet.OLEObjects("ComboBox1").Object
Op1 = Split(operatore, "<")(0)
Op2 = Split(operatore, ">")(1)
End Sub在VBA中,IndexOf不存在。它只存在于VB.NET - MSDN IndexOf中。
发布于 2020-06-18 10:19:37
希望这能在未来为某人节省一些时间:
' indexof
Dim positionInPath As Integer
positionInPath = InStr("C:\Users\2200522\Documents\", "2200522") ' returns 10
' C:\Users\2200522\Documents\
' ^^^ ^
' 123 10
' substring
Dim newPath As String
newPath = Left("C:\Users\2200522\Documents\", 10) ' returns "C:\Users\2"https://stackoverflow.com/questions/48311532
复制相似问题