+ Reply to Thread
Results 1 to 8 of 8

File not found in FileDateTime Function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124

    File not found in FileDateTime Function

    I have an error mentioned in the title. To me it looks ok especially when I debug.print it seems ok and opens that file as well.



    
    
    Sub TensionTime()
    Dim sPath As String
    Dim sFile As String
    Dim sDir As String
    Dim oLB As Workbook
    Dim namee As String
    Dim aveht As Range
    Dim avest1 As Range
    Dim avest2 As Range
    Dim filedate As Date
     
    sPath = "J:\WHP Facility Folder\Arch 3 a - 909 - Projects Raw Data\Winding\"
    sDir = FileSystem.Dir(sPath & "*" & namee & "*" & ".csv", vbNormal)
    
    Do Until LenB(sDir) = 0
       Debug.Print sDir
        Set oLB = Workbooks.Open(sPath & sDir)
        
        ' -- Do Stuff
        Workbooks(sDir).Worksheets(1).Activate
       
            Range("F2").Select
        Set aveht = Range(Selection, Selection.End(xlDown))
        
        
        Workbooks("Date vs Spool Tension").Worksheets(1).Activate
        
        Range("D16") = WorksheetFunction.AverageIf(aveht, ">0")
        filedate = FileDateTime(sDir)
        
         Exit Sub
        
        
        '=AVERAGEIFS(F5:AM5,F5:AM5,"> 0",F$2:AM$2,"total")
        '
        If oLB.Saved = False Then oLB.Save
        oLB.Close False
        sDir = Dir$
    Loop
    
    
    
    
    
    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: File not found in FileDateTime Function

    Perhaps because you are including the '*' character (which is not permitted in a file name) in the sDir variable ?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124

    Re: File not found in FileDateTime Function

    Quote Originally Posted by Richard Buttrey View Post
    Perhaps because you are including the '*' character (which is not permitted in a file name) in the sDir variable ?
    Hi
    Seems that you are right. Have any ideas how to overcome this issue? P.S. I need to use "**" for the name variation

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: File not found in FileDateTime Function

    Hi,

    Since you imply the file name variable bit changes then you must use a variable and allocate the string of varying characters to the variable before you encounter the line of code. And since you seem to have both a preceding and succeeding variable string you first need to Dim two variables for the changing bit of the file name. e.g.

    Dim stFileNameVar1 As String
    Dim stFileNameVar2 As String
    Then allocate the actual file name. e.g. supposing the characters for the file name variations are in cells A1 and A2 on Sheet1 then

    stFileNameVar1 = Sheet1.Range("A1")
    stFileNameVar2 = Sheet1.Range("A2")
    Then your line of code will be

    sDir = FileSystem.Dir(sPath & stFileNameVar1  & YourFixedFileName & stFileNameVar2 & ".csv", vbNormal)

  5. #5
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124

    Re: File not found in FileDateTime Function

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Since you imply the file name variable bit changes then you must use a variable and allocate the string of varying characters to the variable before you encounter the line of code. And since you seem to have both a preceding and succeeding variable string you first need to Dim two variables for the changing bit of the file name. e.g.

    Dim stFileNameVar1 As String
    Dim stFileNameVar2 As String
    Then allocate the actual file name. e.g. supposing the characters for the file name variations are in cells A1 and A2 on Sheet1 then

    stFileNameVar1 = Sheet1.Range("A1")
    stFileNameVar2 = Sheet1.Range("A2")
    Then your line of code will be

    sDir = FileSystem.Dir(sPath & stFileNameVar1  & YourFixedFileName & stFileNameVar2 & ".csv", vbNormal)

    It did not work
    Still says file not found.
    I have declared string variable and singed value "*" to it and then used in the filename as suggested.


    [CODE][/
     Sub TensionTime()
    Dim sPath As String
    Dim sFile As String
    Dim sDir As String
    Dim oLB As Workbook
    Dim namee As String
    Dim aveht As Range
    Dim avest1 As Range
    Dim avest2 As Range
    Dim filedate As Date
      Dim lastRow As Long
    Dim valueht As Range
    Dim star As String
     namee = Range("A1")
    star = "*"
    
    If namee = "CA" Then
    
    sPath = "J:\WHP Facility Folder\Arch 3 a - 909 - Projects Raw Data\Winding\"
    sDir = FileSystem.Dir(sPath & star & namee & star & ".csv", vbNormal)
    
    Do Until LenB(sDir) = 0
       Debug.Print sDir
        Set oLB = Workbooks.Open(sPath & sDir)
        
        ' -- Do Stuff
        Workbooks(sDir).Worksheets(1).Activate
       
        
       Range("F2").Select
        Set aveht = Range(Selection, Selection.End(xlDown))
        
        
        Workbooks("Date vs Spool Tension").Worksheets(1).Activate
        
    
    
    lastRow = Range("f14").End(xlDown).Row
    
    Range("f" & lastRow + 1).Select
    
    
     Selection = WorksheetFunction.AverageIf(aveht, ">0")
        
     
    
        
        filedate = FileDateTime(sDir)
       lastRow = Range("b14").End(xlDown).Row
    
    Range("b" & lastRow + 1).Select
    
    
    Selection = FileDateTime(sDir)
        
       'spool tension 1
        Workbooks(sDir).Worksheets(1).Activate
       
        
       Range("l2").Select
        Set aveht = Range(Selection, Selection.End(xlDown))
        
        
        Workbooks("Date vs Spool Tension").Worksheets(1).Activate
        
    
    
    lastRow = Range("i14").End(xlDown).Row
    
    Range("i" & lastRow + 1).Select
    
    
     Selection = WorksheetFunction.AverageIf(aveht, ">0")
       '
          'spool tension 2
        Workbooks(sDir).Worksheets(1).Activate
       
        
       Range("m2").Select
        Set aveht = Range(Selection, Selection.End(xlDown))
        
        
        Workbooks("Date vs Spool Tension").Worksheets(1).Activate
        
    
    
    lastRow = Range("l14").End(xlDown).Row
    
    Range("l" & lastRow + 1).Select
    
    
     Selection = WorksheetFunction.AverageIf(aveht, ">0")
     '
       'speed
           Workbooks(sDir).Worksheets(1).Activate
       
        
       Range("b2").Select
        Set aveht = Range(Selection, Selection.End(xlDown))
        
        
        Workbooks("Date vs Spool Tension").Worksheets(1).Activate
        
    
    
    lastRow = Range("d14").End(xlDown).Row
    
    Range("d" & lastRow + 1).Select
    
    
     Selection = WorksheetFunction.AverageIf(aveht, ">0")
        
        
      
        '
        If oLB.Saved = False Then oLB.Save
        oLB.Close False
        sDir = Dir$
    Loop
    
    End If
    CODE]

  6. #6
    Forum Contributor
    Join Date
    02-23-2015
    Location
    united kingdom
    MS-Off Ver
    14.0.7143.5000 (32-bit)
    Posts
    124

    Re: File not found in FileDateTime Function

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Since you imply the file name variable bit changes then you must use a variable and allocate the string of varying characters to the variable before you encounter the line of code. And since you seem to have both a preceding and succeeding variable string you first need to Dim two variables for the changing bit of the file name. e.g.

    Dim stFileNameVar1 As String
    Dim stFileNameVar2 As String
    Then allocate the actual file name. e.g. supposing the characters for the file name variations are in cells A1 and A2 on Sheet1 then

    stFileNameVar1 = Sheet1.Range("A1")
    stFileNameVar2 = Sheet1.Range("A2")
    Then your line of code will be

    sDir = FileSystem.Dir(sPath & stFileNameVar1  & YourFixedFileName & stFileNameVar2 & ".csv", vbNormal)
    I have solved it.
    Thanks for help.
    The problem was that in the function FileDateTime(sDir) , the sDir was just the name of file and it should be entire path+filename

  7. #7
    Registered User
    Join Date
    01-08-2022
    Location
    kurdistan
    MS-Off Ver
    2019
    Posts
    1

    Re: File not found in FileDateTime Function

    pls how u do that im so lost
    HTML Code: 
    pls help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. FileDateTime for a file at an ftp location
    By Nwanda in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2014, 02:40 AM
  2. [SOLVED] Shell function gives File not Found error
    By jewelsharma in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2014, 09:38 PM
  3. [SOLVED] Message (in one window) for each file found/not found
    By kboy1289 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-08-2013, 04:03 PM
  4. FileDateTime function - how to make it authomatic?
    By bondcrash in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2006, 09:55 AM
  5. Put only date (not time too) in variable from FileDateTime function
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2006, 02:10 AM
  6. [SOLVED] File or function not found error
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2005, 02:05 PM
  7. FileDateTime for Internet web page
    By Mogwai in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-02-2005, 05:05 PM

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