Results 1 to 3 of 3

Thread: with Application.FileSearch

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    1

    with Application.FileSearch

    Hi guys.

    Looking for an alternative to use in the following example for the with Application.FileSearch. I'm aware that this line of code became unsupported in 2007. We skipped the upgrade to 2007 and went from 2003 - 2010. Thank you in advance! Have put the whole section of code for context.

    Code:
    Option Explicit
    
    Const DIALOG_NAME = "NameSakes”
    Const OffencePath = "U:\Location"
    Dim I As Integer
    Dim NameSake As String
    Dim FoundFiles As Integer
    Dim FileName As String
    
    Private Sub cmdOK_Click()
    
        Application.ScreenRefresh
        Application.ScreenUpdating = False
        
        Namesake = txtNamesake.Text
    
        If Len(Namesake) = 1 Then
            Namesake = "00" + Namesake
        ElseIf Len(Namesake) = 2 Then
            Namesake = "0" + Namesake
        End If
    
        Namesake = "INF*" + Namesake
    
       With Application.FileSearch
         .FileName = Namesake + ".doc"
            .LookIn = NamesakePath
          .Execute
            
            FoundFiles = .FoundFiles.Count
            
            If FoundFiles < 1 Then
                MsgBox (Namesake + " is not a valid Namesake." + vbCrLf + vbCrLf + _
                    "Please re-enter the Namesake number!"), vbOKOnly & vbInformation, _
                    DIALOG_NAME
    '               frmNameSake.Show
            Else
            
                FileName = .FoundFiles.Item(1)  'NamesakePath + "\" + Namesake + ".doc"
                'FileName = NamesakePath + "\" + Namesake + ".doc"
                Selection.InsertFile FileName
                Unload frmNameSake
                Application.Run "NextBookmark"
            
            End If
                
        End With
    
    End Sub
    Last edited by Siddharth Rout; Sep 1st, 2014 at 03:34 PM. Reason: Added Code Tags

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: with Application.FileSearch

    Welcome to VBForums

    Thread moved to the 'Office Development/VBA' forum... which is where questions about using the "VB Editor" in Office products belong

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: with Application.FileSearch

    you can use filesystemobject
    if you search application.filesearch alternative you should find several alternatives with code
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width