#Sub GetIP()
Dim DFWB As Workbook 'TM Tool
Dim NewWb As Workbook 'New Data sheet for all linked Ip addresess
Dim DataWb As Workbook 'TM Monitoring Spreadsheet
Dim DataWbs As Worksheet
Dim rtable As Range
Dim Flist As Worksheet
Dim NewWbs As Worksheet
Dim wkb As Workbook
Dim Tb As TextBox
Dim i As Integer
Set DFWB = ThisWorkbook
Set NewWb = Workbooks.Add(template:=xlWBATWorksheet)
' you must change the LookIn line of code to the Folder you wish to search
Set fs = Application.FileSearch
With fs
.LookIn = "Data Location"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set DataWb = Workbooks.Open(.FoundFiles(i))
DFWB.Activate
DR = DataFm1.TextBox1.Value
Set NewWbs = NewWb.Worksheets(1)
Lastrow = NewWbs.Cells(Rows.Count, 2).End(xlUp).Row
Headln = Lastrow + 2
Nextrow = Headln + 1
Lastrow = Lastrow + 1
DataWb.Activate
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Set DataWbs = Worksheets(1)
DataWbs.Range("A1").AutoFilter Field:=WorksheetFunction.Match("IPAddr", DataWbs.Rows(1), 0), Criteria1:=DR, Operator:= _
xlAnd
Set rtable = DataWbs.Range("A1").CurrentRegion
NewWbs.Cells(Headln, 1).Value = "FileName"
NewWbs.Cells(Headln, 1).Font.Bold = True
NewWbs.Cells(Headln, 1).Font.Size = 14
rtable.Copy Destination:=NewWbs.Cells(Nextrow, 1)
NewWbs.Cells(Headln, 2) = DataWb.Name
NewWbs.Cells(Headln, 2).Font.Size = 14
NewWbs.Cells(Headln, 2).Font.Bold = True
DataWb.Activate
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
ActiveWorkbook.Close SaveChanges:=False
Next i
End If
End With
NewWbs.Activate
NewWbs.Columns("A:K").AutoFit
For Each NewWbs In Worksheets
NewWbs.Range("A2:A" & NewWbs.Rows.Count).RowHeight = 20
Next NewWbs
Fname = Format(Now, "dd.mm.yyyy") & " " & "IPAddr " & DR & ".xls"
Location = "\\irf00969\Datafile\"
NewWb.SaveAs Filename:=Location & Fname
End Sub#
I have the above code that looks for an IP aaddres from multiple workbooks located in a folder, it then reports all instances to a new file.
I have highlighted some code above in RED I would like help with
1.
Message box the result of the foundfiles.count
Ask the user how many files they would like to use? Inputbox
only use the number of files requested from the inputbox
2.
We are in the process in migrating from Excel 2003 to Excel 2013, I belive .Filesearch will not work does anybody have a work around.
Thanks
Ray
Dim DFWB As Workbook 'TM Tool
Dim NewWb As Workbook 'New Data sheet for all linked Ip addresess
Dim DataWb As Workbook 'TM Monitoring Spreadsheet
Dim DataWbs As Worksheet
Dim rtable As Range
Dim Flist As Worksheet
Dim NewWbs As Worksheet
Dim wkb As Workbook
Dim Tb As TextBox
Dim i As Integer
Set DFWB = ThisWorkbook
Set NewWb = Workbooks.Add(template:=xlWBATWorksheet)
' you must change the LookIn line of code to the Folder you wish to search
Set fs = Application.FileSearch
With fs
.LookIn = "Data Location"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set DataWb = Workbooks.Open(.FoundFiles(i))
DFWB.Activate
DR = DataFm1.TextBox1.Value
Set NewWbs = NewWb.Worksheets(1)
Lastrow = NewWbs.Cells(Rows.Count, 2).End(xlUp).Row
Headln = Lastrow + 2
Nextrow = Headln + 1
Lastrow = Lastrow + 1
DataWb.Activate
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Set DataWbs = Worksheets(1)
DataWbs.Range("A1").AutoFilter Field:=WorksheetFunction.Match("IPAddr", DataWbs.Rows(1), 0), Criteria1:=DR, Operator:= _
xlAnd
Set rtable = DataWbs.Range("A1").CurrentRegion
NewWbs.Cells(Headln, 1).Value = "FileName"
NewWbs.Cells(Headln, 1).Font.Bold = True
NewWbs.Cells(Headln, 1).Font.Size = 14
rtable.Copy Destination:=NewWbs.Cells(Nextrow, 1)
NewWbs.Cells(Headln, 2) = DataWb.Name
NewWbs.Cells(Headln, 2).Font.Size = 14
NewWbs.Cells(Headln, 2).Font.Bold = True
DataWb.Activate
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
ActiveWorkbook.Close SaveChanges:=False
Next i
End If
End With
NewWbs.Activate
NewWbs.Columns("A:K").AutoFit
For Each NewWbs In Worksheets
NewWbs.Range("A2:A" & NewWbs.Rows.Count).RowHeight = 20
Next NewWbs
Fname = Format(Now, "dd.mm.yyyy") & " " & "IPAddr " & DR & ".xls"
Location = "\\irf00969\Datafile\"
NewWb.SaveAs Filename:=Location & Fname
End Sub#
I have the above code that looks for an IP aaddres from multiple workbooks located in a folder, it then reports all instances to a new file.
I have highlighted some code above in RED I would like help with
1.
Message box the result of the foundfiles.count
Ask the user how many files they would like to use? Inputbox
only use the number of files requested from the inputbox
2.
We are in the process in migrating from Excel 2003 to Excel 2013, I belive .Filesearch will not work does anybody have a work around.
Thanks
Ray