所有。我的代码是这样的:
Sub mySub
Public Const strVarA As String = "AA"
Public Const strVarB As String = "BB"
Public Const strVarC As String = "CC"
Dim myStrArray() As String
Dim myString As String
myStrArray = ["strVarA", "strVarB", "strVarC"]
For i = 0 To 2
myURL = "http://www.yahoo.com/news/" & myStrArray(i) & ".html" <--- Here, wrong
'//do something.
Next i
End Sub
我的目的是在For循环中,myStrArray(0)应该在URL中放置其常量值“AA”, 像这样:
"http://www.yahoo.com/news/AA.html"
因为URL在其链接中使用“AA”。但代码总是放“strVarA”,就像这样:
"http://www.yahoo.com/news/strVarA.html"
类似于循环到myStrArray(1)时,它应该在URL中放置“BB”,myStrArray(2)应该在URL中放置“CC”。我尝试了很多方法,没有运气。有人对此有经验和建议吗?谢谢!
答案 0 :(得分:0)
尝试以下代码:
Sub mySub()
Const strVarA As String = "AA"
Const strVarB As String = "BB"
Const strVarC As String = "CC"
'Dim myStrArray() As String
Dim myString As String
myStrArray = Array("strVarA", "strVarB", "strVarC")
For i = LBound(myStrArray) To UBound(myStrArray)
myURL = "http://www.yahoo.com/news/" & myStrArray(i) & ".html"
'//do something.
Next i
End Sub
评论后更新
Sub mySub()
Dim myStrArray As Variant
myStrArray = Array("AA", "BB", "CC")
For i = LBound(myStrArray) To UBound(myStrArray)
myurl = "http://www.yahoo.com/news/" & myStrArray(i) & ".html"
MsgBox myurl
Next
End Sub