合并两个vba功能 [英] merging two vba functions

查看:135
本文介绍了合并两个vba功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以合并这两个函数
i试图合并这两个函数



第一个函数

 函数findimage(Path As String,ImageList As String)
Dim results
Dim x As Long
Dim dc'double comma
result = Split(ImageList,,)
如果不正确(Path,1)=\Then Path = Path& \
对于x = 0到UBound(results)
results(x)= Len(Dir(Path& results(x)))> 0
下一个
dc = InStr(ImageList,,,)
如果dc = 0然后
findimage = Join(results,,)
Else
findimage =(Double_comma)
如果
结束函数

secound函数在...下面...
在这个模式变量可以从ImageList变量的第一个函数的帮助下... ....

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

第二个功能是...

 函数getFileCount(DirPath As String,ParamArray Patterns()As Variant)As Integer 
Dim MyFile As String
Dim count As Integer,x As Long
如果不正确(DirPath,1)=\然后DirPath = DirPath& \
MyFile = Dir(DirPath,vbDirectory)
尽管MyFile<>
对于x = 0到UBound(模式)
如果MyFile喜欢模式(x)然后
count = count + 1
退出
结束If
Next
MyFile = Dir()
循环
getFileCount = count
结束函数


解决方案

 函数findimage(Path As String,ImageList As String)
Dim results
Dim x As Long
Dim dc'double comma
Dim extension As String
results = Split(ImageList,,)
如果不正确(路径,1)=\ 然后Path = Path& \
对于x = 0到UBound(results)
如果Len(Dir(Path& results(x)))> 0然后
result(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,,,)
如果dc = 0然后
findimage = Join(results,,)
Else
findimage =(Double_comma)
End If
End Function

函数getFileCount(DirPath As String,ParamArray Patterns()As Variant)As Integer
Dim MyFile As String
Dim count As Integer, x As Long
如果不正确(DirPath,1)=\然后DirPath = DirPath& \
MyFile = Dir(DirPath,vbDirectory)
尽管MyFile<>
对于x = 0到UBound(模式)
如果MyFile喜欢模式(x)然后
count = count + 1
退出
结束If
Next
MyFile = Dir()
循环
getFileCount = count
结束函数


can someone please merge these two functions i am trying to merge these two functions

first function

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 function is below... in this Patterns variable can be taken from ImageList variable of first function with help of this....

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

second function is...

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

解决方案

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

这篇关于合并两个vba功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆