Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2002
    Posts
    55

    Unanswered: Wildcard file search...

    Is there a way using vba to have a wildcard search for a file?

    I have a database that propagates data to a word document. The document naming structure includes a revision date

    (e.g., "Template (12/02/2002).dot")

    I would like to have the code simply look to open based on template and not the date.

    Thanks,

    Hirk

  2. #2
    Join Date
    Nov 2002
    Location
    Hillsboro, OR, USA
    Posts
    59
    I have used this before:

    Code:
    ...
           With Application.FileSearch
        
                .NewSearch
                .LookIn = YourDirectoryPath
                .SearchSubFolders = False
                .FileName = YourSearchString
                .MatchTextExactly = False
        
                .Execute
                
                 For intLoop = 1 To .FoundFiles.Count
    
                    debug.print   .FoundFiles(intLoop)
                  
                 Next intLoop
           
            End With
    ...
    Let me know if you need more explanation,

    Brian
    Last edited by bri; 12-02-02 at 16:26.

  3. #3
    Join Date
    Feb 2002
    Posts
    55

    Arrow Sample code

    Thanks Bri,

    I am not 100% certain how to fit that logic into what I am looking at or if I should rework entirely (I'm still gettting the hang of VB).

    I've attached my code below and would appreciate any input you might have.

    '****************************************
    Private Sub Print_Click()

    Dim DocToUse As String
    Dim FileLocation As String
    Dim appWord As New Word.Application

    FileLocation = "C:\File Location\"

    If lngIndicatorID.Value = 1 Then

    DocToUse = "file1.dot"

    ElseIf lngIndicatorID.Value = 2 Then

    DocToUse = "file2.dot"

    End If

    With appWord

    .Documents.Add FileLocation & DocToUse
    .ActiveDocument.ShowSpellingErrors = False

    .Selection.Goto wdGoToBookmark, Name:="Name"
    .Visible = True
    appWord.Selection.TypeText Forms!frm_Requests!strName

    If strAddress <> "" Then

    .Selection.Goto wdGoToBookmark, Name:="Address"
    .Visible = True
    appWord.Selection.TypeText Me!strAddress

    End If

    .Selection.Goto wdGoToBookmark, Name:="City"
    .Visible = True
    appWord.Selection.TypeText Me!strReqCity

    .Selection.Goto wdGoToBookmark, Name:="State"
    .Visible = True
    appWord.Selection.TypeText Me!strReqState

    .Selection.Goto wdGoToBookmark, Name:="Zip"
    .Visible = True
    appWord.Selection.TypeText Me!lngReqZipCode

    .Selection.Goto wdGoToBookmark, Name:="Date"
    .Visible = True
    appWord.Selection.TypeText Me!dtmResponseDate

    End With

    End Sub
    '****************************************

    Thanks,

    Hirk

  4. #4
    Join Date
    Oct 2004
    Posts
    10

    Opening the file

    I adjusted the following code for what I required: but what code do I use to open the file that it has found?

    With Application.FileSearch

    .NewSearch
    .LookIn = YourDirectoryPath
    .SearchSubFolders = False
    .FileName = YourSearchString
    .MatchTextExactly = False

    .Execute

    For intLoop = 1 To .FoundFiles.Count

    debug.print .FoundFiles(intLoop)

    Next intLoop

    End With

Posting Permissions

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