-
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!
-
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'
-
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules