VBA中的SQL"%"等效项

max*_*dus 3 excel vba excel-vba

在VBA中是否有任何SQL等效的"%"符号?我需要返回几个文件,只是中间有一些字符.

帮助真的很感激!

例如,这是我的代码:我需要从该网页下载名称为2013的所有文件,并以不同方式保存和调用它们.这个任务可能吗?

Sub Sample()
    Dim strURL As String
    Dim strPath As String
    Dim i As Integer

    strURL = "http://cetatenie.just.ro/wp-content/uploads/Ordin-********.2013.pdf"

    strPath = "C:\Documents and Settings\ee28118\Desktop\178.pdf"

    Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)

    If Ret = 0 Then
        MsgBox "File successfully downloaded"
    Else
        MsgBox "Unable to download the file"
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

小智 6

您可以使用Like运算符.

模式中的字符匹配字符串

? Any single character. 
* Zero or more characters. 
# Any single digit (0–9). 
[charlist] Any single character in charlist. 
[!charlist] Any single character not in charlist 
Run Code Online (Sandbox Code Playgroud)

示例:

Dim MyCheck
MyCheck = "aBBBa" Like "a*a"    ' Returns True.
MyCheck = "F" Like "[A-Z]"    ' Returns True.
MyCheck = "F" Like "[!A-Z]"    ' Returns False.
MyCheck = "a2a" Like "a#a"    ' Returns True.
MyCheck = "aM5b" Like "a[L-P]#[!c-e]"    ' Returns True.
MyCheck = "BAT123khg" Like "B?T*"    ' Returns True.
MyCheck = "CAT123khg" Like "B?T*"    ' Returns False.
Run Code Online (Sandbox Code Playgroud)