Results 1 to 5 of 5

Thread: Vba - Check String/Text From Multiple Workbook Without Opening All Files

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    37
    Rep Power
    0

    Vba - Check String/Text From Multiple Workbook Without Opening All Files

    hi all..

    i have 5 excel files with the same format and the same name sheet (Sheet1) into 1 folder
    i want macro to determine or check if one of files or more 1 files contains string/text (any text) but only in range B6 till O11 into Sheet1 WITHOUT opening files one by one, and if found string/text into 5 files show Message box "Founded 2 files with name files e.g. data_1555, data_33" -- depend how many string/text can founded into 5 files otherwise "Not Found" if not found string
    my excel files is random names.
    my folder names file into path in D:\Target
    here my attachment 5 file names

    any help, greatly appreciated..

    susanto



    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA


    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwplzlpYpmRqjGZem14AaABAg. 9hrvbYRwXvg9ht4b7z00X0
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgyOGlCElBSbfPIzerF4AaABAg. 9hrehNPPnBu9ht4us7TtPr
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwHjKXf3ELkU4u4j254AaABAg. 9hr503K8PDg9ht5mfLcgpR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw1-OyZiDDxCHM2Rmp4AaABAg.9hqzs_MlQu-9ht5xNvQueN
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9htG01cKBzX
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htJ6TpIOXR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htOKs4jh3M
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugygb0YiLOI7fG1zQSx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugygb0YiLOI7fG1zQSx4AaABAg. 9htWqRrSIfP9i-fyT84gqd
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugygb0YiLOI7fG1zQSx4AaABAg. 9htWqRrSIfP9i-kIDl-3C9
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9i57J9GEOUB
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9i58MGeM8Lg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9i59prk5atY
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwaWs6XDXdQybNb8tZ4AaABAg. 9i5yTldIQBn9i7NB1gjyBk
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxV9eNHvztLfFBGsvZ4AaABAg. 9i5jEuidRs99i7NUtNNy1v
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugx2zSXUtmLBSDoNWph4AaABAg. 9i3IA0y4fqp9i7NySrZamd
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9i7Qs8kxEqH
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9i7TqGQYqTz
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAJSNws8Zz
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAJvZ6kmlx
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAK0g1dU7i
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKCDqNmnF
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKHVSTGHy
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKSBKPcJ6
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKgL6lrcT
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKlts8hKZ
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAKrX7UPP0
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz4oMZ09MKcExYlWf94AaABAg. 9hwsCHaKX6A9iAL5MSjWpA
    Attached Files Attached Files
    Last edited by DocAElstein; 07-09-2023 at 07:55 PM.

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,429
    Rep Power
    10
    Hello Muhammad
    We can, with Excel, do a couple of very simple things on closed workbooks.
    _1 Get values from the cells
    _2 Use the closed workbook ranges in some Excel formulas
    There are also more advanced things that can be done

    I will initially do a simple solution,
    Simple Solution _1

    We can get for example the value in cell B6 in Sheet1 of data_1555.xlsx with a closed workbook referrence formula like of this form
    ='C:\AFolder\Target\[data_1555.xlsx]Sheet1'!$B$6
    we may now change that to a relative reference, or “fixed vector” formula thus
    ='C:\AFolder\Target\[data_1555.xlsx]Sheet1'!B6
    which can then be applied across a multi cell range to return us all the values from a range. It will keep its relative cell value position. For convenience we can apply this over a temporary range of the same size as the data range. This will effectively import the values from the closed workbook data range into the temporary range

    Once we have those values, we can think of a way to check to see if they are all empty. Just one example would be to count how many 0s **( For this solution it would assume that you do not have any cells filled with a 0 )
    (**A closed workbook referrence formula will return a 0 if applied to an empty cell in a closed workbook)


    I assume that all worksheets are named Sheet1. I also need to know the workbook names, but we can get those in a loop using the Dir function, to loop for all files in a folder.
    I will write the macro in a file, OpenBook.xls, which I will initially assume is also in the same folder , ( your Target folder )

    Macro:
    Code:
    Option Explicit
    Sub Solution_1() ' https://excelfox.com/forum/showthread.php/2780-Vba-Check-String-Text-From-Multiple-Workbook-Without-Opening-All-Files?p=16337&viewfull=1#post16337
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = ThisWorkbook.Worksheets.Item(1) ' first woprksheet item - first tab counting from the left
    Dim rngTemp As Range: Set rngTemp = Ws.Range("B6:O11")        ' Any range of the size of the data range, (ex A1:B6 is just as good). We temporarily put our velues from the closed workbook data range here for each workbook we find with  Dir
    Dim Pth As String: Let Pth = ThisWorkbook.Path ' YOU MAY WANT TO CHANGE THIS ####
    Rem 2 loop all files at Pth
    Dim FileName As String
     Let FileName = Dir(Pth & "\*.xlsx", vbNormal) ' this will return the next file meeting path and search criteria  Pth & "\xxxxxxxxxxxx.xlsx"
        Do While FileName <> ""  '  Dir  will only look once in a folder, progresively going down the list, and it will return  ""  once it finds no more files meeting the criteria  Pth & "\xxxxxxxxxxxx.xlsx"
            If FileName <> ThisWorkbook.Name Then  ' YOU MAY NOT NEED THIS IF this file is not in the same folder  ####
             '  like              "='C:\..\Target\[data_1555.xlsx]Sheet1'!B6 "
             Let rngTemp.Value2 = "='" & Pth & "\[" & FileName & "]Sheet1'!B6" ' put the values from the data range in the closed book temporarily in the temporary range of this workbook
             Dim Cnt As Long: Let Cnt = Application.WorksheetFunction.CountIf(Ws.Range("B6:O11"), 0) ' The closed workbook referrence formula in the last line will return a 0 for empty cells.
                If Cnt = 84 Then ' The data range has 84 cells, so if all are empty the closed workbook referrence formula will give all 84 cells  value as  0
                ' if we have 84 cells with  0  in, then there are no cell values in the range
                Else
                ' if we did not count 84 0s then we must have some filled cells
                Dim OutMsg As String, CntOut As Long
                 Let OutMsg = OutMsg & FileName & vbCr & vbLf: Let CntOut = CntOut + 1 ' add file name to output messag foolowe by new line  :  increas count of workbooks with some data in
                End If
            Else '                                 ' YOU MAY NOT NEED THIS IF this file is not in the same folder  ####
            ' we found this workbook using  Dir  ,so we ignore it
            End If '                               ' YOU MAY NOT NEED THIS IF this file is not in the same folder  ####
         Let FileName = Dir ' if I use  Dir  on its own without stuff in ( )  then it uses last search criteria again and looks for next file meeting path criteria    Pth & "\xxxxxxxxxxxx.xlsx"
        Loop ' Do While FileName <> ""
    
    Rem 3 Outpout message
        If Cnt = 0 Then
         MsgBox prompt:="All files are empty of data"
        Else
         MsgBox prompt:="Founded " & CntOut & " unempty files, with names" & vbCr & vbLf & OutMsg
        End If
         
    End Sub

    To test: Put file, OpenBook.xls , in same folder as test files ( in your Target folder )
    Run macro Sub Solution_1()

    Using you test results, should give:

    Test results.JPG



    Alan


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxUbeYSvsBH2Gianox4AaABAg. 9VYH-07VTyW9gJV5fDAZNe
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgyhQ73u0C3V4bEPhYB4AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg. 9fsvd9zwZii9gMUka-NbIZ
    https://www.youtube.com/watch?v=jdPeMPT98QU
    https://www.youtube.com/watch?v=QdwDnUz96W0&lc=Ugx3syV3Bw6bxddVyBx4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Attached Files Attached Files
    Last edited by DocAElstein; 07-12-2023 at 05:05 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    37
    Rep Power
    0
    hi.. DocAElstein.
    thank you so much!!! Brilliant, Working great!!


    Quote Originally Posted by muhammad susanto View Post
    hi.. DocAElstein.
    thank you so much!!! Brilliant, Working great!!
    OK, yous welcome, thanks for the feedback

    Alan
    Last edited by DocAElstein; 01-30-2022 at 03:52 PM.

  4. #4
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    Late in the day, I know. This one looks for strings only (numbers are ignored) in that range:
    Code:
    Sub blah()
    Set fs = CreateObject("Scripting.FileSystemObject")
    Pth = "D:\Target"
    Set f = fs.GetFolder(Pth)
    For Each wb In f.Files
      If InStr(1, wb.Type, "Excel", vbTextCompare) > 0 Then
        With Range("C4") 'use a cell where it doesn't matter
          .Formula2R1C1 = "=SUMPRODUCT(--ISTEXT('" & Pth & "\[" & wb.Name & "]Sheet1'!R6C1:R11C15))"
          If .Value > 0 Then If Len(msg) = 0 Then msg = wb.Name Else msg = msg & vbLf & wb.Name
          .Clear
        End With
      End If
    Next wb
    If Len(msg) > 0 Then
      MsgBox "Workbooks containing any string in range B6:O11 are:" & vbLf & msg
    Else
      MsgBox "None found"
    End If
    End Sub

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-07-2023 at 01:08 PM.

  5. #5
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,429
    Rep Power
    10
    Its never late here, Pascal, - furthering the subject at any time is what we’re about,
    I actually wanted to try at a solution like yours, but I am not so well clued up generally on formulas, and I am not so sure which ones work on closed workbooks. Some don’t for some reason I don’t know yet.
    But I expected a solution like you did might be a bit more efficient as you just use a temporary cell rather than a temporary range as mine did.
    (You got a small typo I think, .Formula2R1C1 should be .FormulaR1C1)

    ( I always use .Value when I put a formula into a cell with coding. Its just a personal preference based on a (very likely dodgy) “Alan theory” that .Value applied to a cell in coding is seen as if you type stuff in manually in the spreadsheet, and the thing telling Excel it's a formula is the _"="_, just as it would be if you typed it in manually in the spreadsheet
    .FormulaR1C1 is probably the more better and correct way, but I like to indulge in my fantasy theories,
    )


    Alan

    Code:
    '  Pascal    https://excelfox.com/forum/showthread.php/2780-Vba-Check-String-Text-From-Multiple-Workbook-Without-Opening-All-Files?p=16356&viewfull=1#post16356
    Sub blah()
    Dim Fs As Object, Pth As String, F As Variant, Wb As Object, Msg As String
    Set Fs = CreateObject("Scripting.FileSystemObject")
     Let Pth = ThisWorkbook.Path '"D:\Target"
    Set F = Fs.GetFolder(Pth)
        For Each Wb In F.Files
          If InStr(1, Wb.Type, "Excel", vbTextCompare) > 0 Then
            With Range("C4") 'use a cell where it doesn't matter
             '.FormulaR1C1 = "=SUMPRODUCT(--ISTEXT('" & Pth & "\[" & Wb.Name & "]Sheet1'!R6C1:R11C15))"
            .Value = "=SUMPRODUCT(--ISTEXT('" & Pth & "\[" & Wb.Name & "]Sheet1'!R6C1:R11C15))"
                If .Value > 0 Then If Len(Msg) = 0 Then Msg = Wb.Name Else Msg = Msg & vbLf & Wb.Name
             .Clear
            End With
          End If
        Next Wb
        If Len(Msg) > 0 Then
          MsgBox "Workbooks containing any string in range B6:O11 are:" & vbLf & Msg
        Else
          MsgBox "None found"
        End If
    End Sub
    Last edited by DocAElstein; 01-30-2022 at 08:43 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Replies: 114
    Last Post: 03-04-2024, 02:39 PM
  2. Replies: 101
    Last Post: 06-11-2020, 02:01 PM
  3. Replies: 2
    Last Post: 04-14-2013, 09:15 PM
  4. Replies: 2
    Last Post: 01-29-2013, 02:45 PM
  5. Replies: 2
    Last Post: 09-24-2012, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •