Consulting

Results 1 to 4 of 4

Thread: Solved: check file for xls and xlsx extensions

  1. #1
    VBAX Regular
    Joined
    Mar 2008
    Posts
    24
    Location

    Solved: check file for xls and xlsx extensions

    I have this code, which checks for xls extensions. How do I make it so it check BOTH xls AND xlsx?

    [vba]
    Sub File_Exists()
    Dim fso
    Dim file As String
    Dim file2 As String
    file1 = ActiveWorkbook.Name

    Application.ScreenUpdating = False

    For Each c In Worksheets(1).Range("F17:F5000").Cells
    If c.Value <> "" Or c.Interior.ColorIndex = 3 Or c.Offset(rowoffset:=0, columnoffset:=-2).Value = "Y" Then '****

    file = "C:\Documents and Settings\JP\Desktop\JP\Accent\" & c.Value & ".xls" '".xlsx" 'file = "C:\Documents and Settings\JP\Desktop\JP\Accent\" & c.Value & ".xlsx"
    'file2 = "C:\Documents and Settings\JP\Desktop\JP\Accent\" & c.Value & ".xlsx"

    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FileExists(file) Then
    MsgBox file & " was not located.", vbInformation, "File Not Found"
    c.Offset(rowoffset:=0, columnoffset:=26).Select
    Selection.Value = "No Template"
    c.Interior.ColorIndex = 3
    Else

    End If

    End If

    Next

    MsgBox "All templates files checked."

    Application.ScreenUpdating = True

    End Sub
    [/vba]
    Thanks, guys!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    How about
    [VBA]
    Dim Pth As String
    Pth = "C:\Documents and Settings\JP\Desktop\JP\Accent\"
    file = Pth & Dir(Pth & c.Value & ".xl*")
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Mar 2008
    Posts
    24
    Location
    BEAUTIFUL!

  4. #4
    VBAX Regular
    Joined
    Mar 2008
    Posts
    24
    Location
    Thank you kindly, sir!

Posting Permissions

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