2

全部。我的代码是这样的:

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) 应该将其常量值“AA”放在 URL 中,如下所示:

"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”。我尝试了很多方法,没有运气。有人对此有经验和建议吗?谢谢!

4

1 回答 1

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
于 2013-06-03T01:20:47.117 回答