Results 1 to 8 of 8

Thread: Loop through a folder and find word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Member rollis13's Avatar
    Join Date
    Nov 2012
    Posts
    36
    Rep Power
    0
    Have a try with something like this:
    Code:
    Option Explicit
    Sub general()
        Dim z As Long, e As Long, a As Long, b As Range
        Dim f As String, m As String, n As String
        Sheets("Sheet1").Select
        'Cells(1, 1) = "=cell(""filename"")"      '<=not working
        Cells(1, 1) = "filename"      '<=changed
        'Cells(1, 2) = "=left(A1,find(""["",A1)-1)"      '<=didn't understand
        Cells(1, 2) = "E:\Test\"      '<=to be adjusted
        Cells(2, 1).Select
        f = Dir(Cells(1, 2) & "*.xls")
        Do While Len(f) > 0
            ActiveCell.Formula = f
            ActiveCell.Offset(1, 0).Select
            f = Dir()
        Loop
        m = InputBox("Enter search string")
        n = InputBox("Enter replacement string") 'common replacement
        z = Cells(Rows.Count, 1).End(xlUp).Row
        Application.ScreenUpdating = False      '<=added
         '---test all workbooks found---
        For e = 2 To z
            If Cells(e, 1) <> ActiveWorkbook.Name Then
                Workbooks.Open Filename:=Cells(1, 2) & Cells(e, 1)
                 '---test all sheets within book---
                For a = 1 To Sheets.Count
                    With ActiveWorkbook.Sheets(a)
                         '---test all used cells within sheet---
                        For Each b In .UsedRange.Cells
                            If b.Value = m Then
                                b = n
                            End If
                        Next b
                    End With
                Next a
                ActiveWorkbook.Close True
            End If
        Next e
        '---------------------------------------------------
        Application.ScreenUpdating = True      '<=added
        MsgBox "collating is complete."
    End Sub
    Last edited by rollis13; 12-08-2012 at 03:04 PM.

Similar Threads

  1. Replies: 7
    Last Post: 08-24-2015, 10:58 PM
  2. Replies: 1
    Last Post: 05-21-2013, 11:58 AM
  3. Loop Through And Delete Multiple File Types In A Folder
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 03-30-2013, 04:47 PM
  4. Replies: 1
    Last Post: 10-16-2012, 01:53 PM
  5. Find Parent Folder From Given Folder / File Path
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 05-28-2011, 03:50 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
  •