合并两个vba函数

时间:2016-12-02 12:04:39

标签: excel vba

有人可以合并这两个功能 我正在尝试合并这两个函数

第一个功能

Function findimage(Path As String, ImageList As String)
Dim results
Dim x As Long
Dim dc 'double comma
results = Split(ImageList, ",")
If Not Right(Path, 1) = "\" Then Path = Path & "\"
For x = 0 To UBound(results)
results(x) = Len(Dir(Path & results(x))) > 0
Next
dc = InStr(ImageList, ",,")
If dc = 0 Then
findimage = Join(results, ",")
Else
findimage = ("Double_comma")
End If
End Function

secound功能如下...... 在这个Patterns变量中可以从第一个函数的ImageList变量中获取这个....

Patterns = Mid(ImageList, 1, Application.WorksheetFunction.Search("_", ImageList, 1)) & "#.jpg"

第二个功能是......

Function getFileCount(DirPath As String, ParamArray Patterns() As Variant) As Integer
Dim MyFile As String
Dim count As Integer, x As Long
If Not Right(DirPath, 1) = "\" Then DirPath = DirPath & "\"
MyFile = Dir(DirPath, vbDirectory)
Do While MyFile <> ""
For x = 0 To UBound(Patterns)
If MyFile Like Patterns(x) Then
count = count + 1
Exit For
End If
Next
MyFile = Dir()
Loop
getFileCount = count
End Function

1 个答案:

答案 0 :(得分:2)

Function findimage(Path As String, ImageList As String)
    Dim results
    Dim x As Long
    Dim dc    'double comma
    Dim extension As String
    results = Split(ImageList, ",")
    If Not Right(Path, 1) = "\" Then Path = Path & "\"
    For x = 0 To UBound(results)
        If Len(Dir(Path & results(x))) > 0 Then
            results(x) = True
        Else
            extension = Right(results(x), Len(results(x)) - InStrRev(results(x), "."))
            results(x) = "False(" & getFileCount(Path, "*." & extension) & ")"
        End If
    Next
    dc = InStr(ImageList, ",,")
    If dc = 0 Then
        findimage = Join(results, ",")
    Else
        findimage = ("Double_comma")
    End If
End Function

Function getFileCount(DirPath As String, ParamArray Patterns() As Variant) As Integer
    Dim MyFile As String
    Dim count As Integer, x As Long
    If Not Right(DirPath, 1) = "\" Then DirPath = DirPath & "\"
    MyFile = Dir(DirPath, vbDirectory)
    Do While MyFile <> ""
        For x = 0 To UBound(Patterns)
            If MyFile Like Patterns(x) Then
                count = count + 1
                Exit For
            End If
        Next
        MyFile = Dir()
    Loop
    getFileCount = count
End Function