QA–QC BYUNS – Note – "This site uses cookies from Google to deliver its services to personalize ads and to analyze traffic information about your use of this site is shared with Google, BY USING THIS SITE YOU AGREE TO ITS USE OF COOKIES"

Sunday, April 12, 2020

EXCEL VBA, USE OF COMPID, FSO AND INPUTBOX

Option Explicit
-------------------------------------------
Sub findfileinfolder()

Call CountFiles

End Sub
---------------------------------------------
Private Function CountFiles()
Dim strDirectory As String, strDestFolder As String, strExt As String

strDirectory = InputBox("pl inter path for serch folder")

'strDestFolder = InputBox("pl inter path for output folder")

    Dim myfilesystemobject As Object
    Dim myfiles As Object
    Dim myFile As Object
    Dim Compld As Range
    Dim mystore As Variant
   
    Set myfilesystemobject = CreateObject("Scripting.FileSystemObject")
    Set myfiles = myfilesystemobject.GetFolder(strDirectory).Files
   
    For Each myFile In myfiles
           
       Range("B1").ClearContents
       Range("B1").Value = myFile.Name
       mystore = myFile.Name
       
        Set Compld = Range("A:A").Find(what:=mystore, LookIn:=xlValues, lookat:=xlWhole)
                   
            If Not Compld Is Nothing Then
            'Stop
                 With myFile
                    .Copy strDestFolder & "\" & myFile.Name
                 End With
            Else
            End If
         
    Next myFile
     
    Set myfiles = Nothing
    Set myfilesystemobject = Nothing
End Function



No comments:

Post a Comment

Please do not enter any spam link in the comment box