我有以下代码:
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”。我该如何解决?
答案 0 :(得分:0)
如果你关注的是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。
答案 1 :(得分:0)
希望这可能在将来节省一些时间:
' 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"