Checking to see if a file exists
Eliminate Pivot Table Annoyances
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Checking to see if a file exists

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I'm trying to write some code to check if a file exists in a particular directory, if the file does exist, I want to bring up a message box confirming that the file exists. I would appreciate any suggestions.

    Thanks

    Matt

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Matt


    Full ifo here: http://www.ozgrid.com/VBA/IsWorkbookOpen.htm


    Code:
    Sub DoesWorkBookExist()
    '''''''''''''''''''''''''''''''
    'Written by http://www.Ozgrid.com
    
    'Test to see if a Workbook exists
    ''''''''''''''''''''''''''''''''
    Dim i As Integer
    
    	With Application.FileSearch
    		.LookIn = "C:MyDocuments"
    		'* represents wildcard characters
    		.FileName = "Book*.xls" 
    			If .Execute > 0 Then 'No Workbook
    			      MsgBox "There is no Workbook."
    			Else 'There is a Workbook
    			      MsgBox "The Workbook does not exist"
    			End If
    	End With
    End Sub

  3. #3
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Another option:

    Sub T()
    Dim Pth as String

    Pth = "C:My DocumentsTestFile.xls"

    If Len(Dir(Pth)) > 0 then
    'Found It !
    Else
    MsgBox "Coudln't find it"
    End If
    End Sub
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks again Dave

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Thanks Juan

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com