Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2014, 07:57 AM
ozman86 ozman86 is offline Automation Process of  Schedule Report Output and Report Check Score Card ! Windows 7 64bit Automation Process of  Schedule Report Output and Report Check Score Card ! Office 2010 64bit
Novice
Automation Process of  Schedule Report Output and Report Check Score Card !
 
Join Date: Nov 2014
Posts: 4
ozman86 is on a distinguished road
Default Automation Process of Schedule Report Output and Report Check Score Card !

i have some files that are coming daily to a folder and are replaced my new ones daily . i am using the followingVBA for catching the file and putting the X mark in the excel. But what i really want is to get the today file , sometime the today file is not delivered and the yesterday file is still sitting , so just by catching the name the code put X in the excel sheet , which i do not want.





Code:
Private Sub TestFileExistence()


 If FileFolderExists("\\cf3.pepsico.pvt\psra\Output\BI4\PSRA Day Tracker - Exec.mhtml") And _
       Weekday(Date) = 2 Then
 Range("P4").Value = "X"
End If
End Sub
the module code of the function is following



Code:
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author       : Usman Tariq
'Macro Purpose: Check if a file or folder exists
    On Error GoTo EarlyExit
    If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
    
    EarlyExit:
    On Error GoTo 0
End Function

Doing some research some one asked me to do following thing

your FileFolderExists() function probably utilizes the Filesytem object
and has something like:


Code:
if (fso.fileexists(filename)) then
you need to EITHER modify your FileFolderExists function
to also use:


Code:
set f = fso.getfile(filename)
if (datediff("d",f.datelastmodified,now()) = 0) then

or add a variation of this to your parent macro.
(which runs if the filefolderexists function returns "true")



Dont know where to put In my code , please help


Code:
set f = fso.getfile(filename)
if (datediff("d",f.datelastmodified,now()) = 0) then
in my code
Reply With Quote
  #2  
Old 11-19-2014, 11:52 PM
gmayor's Avatar
gmayor gmayor is offline Automation Process of  Schedule Report Output and Report Check Score Card ! Windows 7 64bit Automation Process of  Schedule Report Output and Report Check Score Card ! Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

What I think you are looking for is:

Code:
Option Explicit
Function TestFileExistence(strFilename) As Boolean
Dim FSO As New FileSystemObject
Dim f As Object
    On Error GoTo Not_Found
    Set f = FSO.GetFile(strFilename)
    If (FSO.FileExists(strFilename)) Then
        If (DateDiff("d", f.DateLastModified, Now()) = 0) Then
            TestFileExistence = True
        End If
    End If
lbl_Exit:
    Set f = Nothing
    Exit Function
Not_Found:
    Resume lbl_Exit
End Function

Sub Macro1()
MsgBox TestFileExistence("C:\Path\Filename.ext")
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automation Process of  Schedule Report Output and Report Check Score Card ! Excel -> PowerPoint multiple presentations - process automation wstach Excel Programming 2 03-18-2014 06:20 AM
Excel to Access to Excel for report automation Nicholaspoe Excel Programming 10 10-08-2013 08:13 PM
Automation Process of  Schedule Report Output and Report Check Score Card ! Who Does What, When Report Times cossie2k Project 1 06-26-2013 05:49 AM
Example Report Hinchy Word 0 10-09-2012 07:00 AM
Report creation. Igtech Excel 1 04-02-2010 03:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft