Sheets Feats
New Member
- Joined
- Apr 21, 2017
- Messages
- 6
I have almost 900 workbooks that I need to mine for data. These workbooks are nearly identical, but through the years the addresses for certain info has changed. I currently have a macro (below) which works nicely that opens each WB, looks for my defined string, and returns the location. For this macro that's all I need, however it takes about 30 minutes to complete since it has to open each one.
Once I have my addresses, I use a separate macro that utilizes ExecuteExcel4Macro which pulls the info I'm ultimately looking for. This process only takes about 30 seconds since it doesn't open each WB. I have not had success using ExecuteExcel4Macro unless I have a specific cell to reference which is why it works for the second scenario and not the first.
Here's the macro I'd like to see work more efficiently. Is there any way to get around opening each WB individually? The focus of my issue is about halfway through the code:
Once I have my addresses, I use a separate macro that utilizes ExecuteExcel4Macro which pulls the info I'm ultimately looking for. This process only takes about 30 seconds since it doesn't open each WB. I have not had success using ExecuteExcel4Macro unless I have a specific cell to reference which is why it works for the second scenario and not the first.
Here's the macro I'd like to see work more efficiently. Is there any way to get around opening each WB individually? The focus of my issue is about halfway through the code:
Code:
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
End With
'variables to build unique file names and how much to repeat
strSearchFor = "Partial String To Search"
RowStart = 4
RowEnd = 883
Set wbCollector = Workbooks("WorkbookThatCollectsTheInfo.xlsm")
ColumnToFill = "L"
PathColumnOffset = -8
FileColumnOffset = -7
SheetName = "Sheet1"
Sheets(SheetName).Range(ColumnToFill & RowStart).Activate
For reps = RowStart To RowEnd
fpath = Sheets(SheetName).Range(ColumnToFill & reps).Offset(0, PathColumnOffset).Value
fname = Sheets(SheetName).Range(ColumnToFill & reps).Offset(0, FileColumnOffset).Value
'*** the focus of my issue, opening each WB to return an address ***
Set owb = Application.Workbooks.Open(fpath & fname)
Set ra = Sheets("SheetInExternalWB").Cells.Find(What:=strSearchFor, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If ra Is Nothing Then
wbCollector.Sheets(SheetName).Range(ColumnToFill & reps).Value = "Not found"
Else
wbCollector.Sheets(SheetName).Range(ColumnToFill & reps).Value = ra.Address
End If
With owb
.Close
End With
Next reps
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
End With