Consulting

Results 1 to 3 of 3

Thread: application.filesearch not working in Excel 2010

  1. #1
    VBAX Newbie
    Joined
    Oct 2013
    Posts
    5
    Location

    application.filesearch not working in Excel 2010

    Hi,

    Can somebody please help. I have searched the internet for this issue and there are loads of posts about it but I am unable to find a resolution to my particular problem. part of the problem is my inability to adapt code that others have posted to suit my problem. I am unable to post my code at this time because I am at home now without my other laptop. Basically, this is what I am trying to do;

    1. Open all Excel files (.xls, one at a time) in a network drive path that is specified in a cell. Lets say the cell is H3 on a worksheet called "Sheet 1".

    2. When each file is open, I need to be able to apply the autofilter, filter two columns, lets say columns 3 and 5 an then select all records in columns a to t for all records that exist and then copy them.

    3. I then need to be able to select the workbook that contains the code (this file) and then paste the data to the next available row on worksheet that is specified in a cell. Lets say the cell is H4 on a worksheet called "Sheet 2".

    4. After each file has been opened and the data pasted to this file, each file can be closed without saving the changes.

    I would be very grateful if anybody could offer any help.

    many thanks.

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    I will wait until you have found your other laptop....

  3. #3
    VBAX Newbie
    Joined
    Oct 2013
    Posts
    5
    Location

    Unhappy Code now attached!

    Quote Originally Posted by stanleds View Post
    Hi,

    Can somebody please help. I have searched the internet for this issue and there are loads of posts about it but I am unable to find a resolution to my particular problem. part of the problem is my inability to adapt code that others have posted to suit my problem. I am unable to post my code at this time because I am at home now without my other laptop. Basically, this is what I am trying to do;

    1. Open all Excel files (.xls, one at a time) in a network drive path that is specified in a cell. Lets say the cell is H3 on a worksheet called "Sheet 1".

    2. When each file is open, I need to be able to apply the autofilter, filter two columns, lets say columns 3 and 5 an then select all records in columns a to t for all records that exist and then copy them.

    3. I then need to be able to select the workbook that contains the code (this file) and then paste the data to the next available row on worksheet that is specified in a cell. Lets say the cell is H4 on a worksheet called "Sheet 2".

    4. After each file has been opened and the data pasted to this file, each file can be closed without saving the changes.

    I would be very grateful if anybody could offer any help.

    many thanks.
    Here is the code. Hope you can help me.

    Sub Update_NR_Month()
    Call Create_Blank2
    Application.StatusBar = "Refreshing Meter List, please be patient!......."
    Dim lCount As Long
    Dim wbResults As Workbook
    Dim wbCodeBook As Workbook
    
    Application.ScreenUpdating = False
    Application.Calculation = xlManual
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    On Error Resume Next
        Set wbCodeBook = ThisWorkbook
            With Application.FileSearch
                .NewSearch
                .LookIn = Sheets("Named Ranges").Range("H2").Value
                .FileType = msoFileTypeExcelWorkbooks
                        If .Execute > 0 Then 'Workbooks in folder
                        For lCount = 1 To .FoundFiles.Count 'Loop through all
                            'Open Workbook x and Set a Workbook variable to it
                            Set wbResults = Workbooks.Open(FileName:=.FoundFiles(lCount), UpdateLinks:=0)
                            
                            'DO YOUR CODE HERE
                            Cells.Select
                            Selection.EntireColumn.Hidden = False
                            Call Autofilter
                            
                            Selection.Autofilter Field:=3, Criteria1:="0"
                            Range("A2").Offset(1, 0).Select
                            Range(ActiveCell, Range("M" & Rows.Count).End(xlUp)).Select
                            Selection.SpecialCells(xlCellTypeVisible).Copy
                            
                            Workbooks("No Reads Grabber.xls").Activate
                            Sheets("Named Ranges").Range("E15").Value.Activate
                            Range("A65535").End(xlUp).Offset(1, 0).Select
                            
                            Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
                            False, Transpose:=False
                            Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
                            False, Transpose:=False
                            wbResults.Close savechanges:=False
                        Next lCount
                    End If
            End With
    On Error GoTo 0
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True
    Call Unmerge_All
    Call Format_Date
    Application.StatusBar = False
    'Call Copy_C
    'Call Copy_KL
    Call Copy_NOPQRSTU
    Call Insert_Row
    Call Format_Meter_Ref
    MsgBox ("No Read Month - Update Complete")
     
    End Sub
    thanks
    Last edited by Aussiebear; 10-08-2013 at 03:00 AM. Reason: Attached tags to code

Posting Permissions

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