Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2006, 11:15 AM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Check if file starting with a pattern exists or no

Hi

I want to check if a file beginning with a fixed pattern, say, "PROGRAM" exists or not. So all files like "PROGRAM", "PROGRAM123", "PROGRAM.xls" and "PROGRAM 15-May-2006.xls" should pass this check. I don't know how this can be done. Please help !

The way I shall use it is

Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(filename) Then
  ' do something
End If

What shoould I append with filename so that all such filenames pass above written test ?
 
Old May 30th, 2006, 08:28 AM
Authorized User
 
Join Date: Mar 2006
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try something like this

Code:
Const File_Loc = "C:\"


Set RiskFile = Application.FileSearch

    With RiskFile
        .NewSearch
        .LookIn = File_Loc
        .Filename = "Program*"

        If .Execute(SortBy:=msoSortByLastModified, sortorder:=msoSortOrderDecending) > 0 Then
            'Do Something        
        End If
    End With







Similar Threads
Thread Thread Starter Forum Replies Last Post
document() - check if a file exists N.Todd XSLT 2 September 19th, 2007 05:50 AM
Check if a file exists on network darrenb Access VBA 2 March 27th, 2007 07:15 PM
hei,anyone know how to check a remote file exists lsj113 C# 2005 3 November 28th, 2006 02:55 AM
check whether a particular session exists or not chayanvinayak PHP How-To 1 May 1st, 2006 04:09 PM
check first to see if the file exists crmpicco Classic ASP Professional 2 December 1st, 2005 12:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.