+ Reply to Thread
Results 1 to 2 of 2

check for file, if available run macro?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-17-2007
    Posts
    3

    check for file, if available run macro?

    At my work we have daily raw data that is released on a server, in excel format. What I would normally do is wait for that data to be posted (usually around 5pm or so), copy and paste the cells into a easier to read report that i send to my work group. Whats frustrating, is that I dont like waiting for the report, it would be nice if it were automatic which would free me to do other things away from my desk.

    So my question is, if there is a report thats based on a set numerical value equal to the previous day. So, the report for today would have been named report09162007.xls, what code would I use if I wanted a macro to automaticly check the server for the new file, if not available, then wait until it is, when its available run the macro that grabs the data i need and have it send off an e-mail to a designated group....

    Any Ideas?

    Thanks in advance?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You would need to use the On Time method to check periodically for the file.
    This UDF checks for a file

    Option Explicit

    Function wbExists(FullFileName As String) As Boolean
    ' returns TRUE if the file exists
        wbExists = Len(Dir(FullFileName)) > 0
    End Function
    Check for the file with

    Sub mainCode()
        Dim sFile  As String
        'you need the path where the file is
        sFile = "C:\Documents and Settings\your name\ReportsFolder\report" & Format(Date - 1, "mmddyy") & ".xls"
        If Not wbExists("sfile") Then
    'keep checking
            checkLater
            Exit Sub
        Else
            'your code
        End If
    End Sub
    Sub checkLater()
        'check each 5 minutes
        Application.OnTime Now + TimeValue("00:05:00"), "mainCode"
    End Sub
    Start the process when the workbook is opened

    Option Explicit
    
    Private Sub Workbook_Open()
    'start the Ontime & run the main macro after 5 minute
    Application.OnTime Now + TimeValue("00:05:00"), "mainCode"
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1