I need the following program to import the .CSV file by todays date. I have looked everywhere but I cannot find what I need.
The name of the CSV file changes every day, so I need to be able to find it by the Date it was modified.
The Lines I need the dates for are lines 15 and 41.
Thanks
Dwight cook
1. Dim NextTime As Date
2. Function LastModTime(FileSpec As String) As Date
3. 'Returns the date-time the file specified by FileSpec (path string) was last modified
4. Dim fs, f, s
5. Set fs = CreateObject("Scripting.FileSystemObject")
6. Set f = fs.GetFile(FileSpec)
7. LastModTime = f.Datelastmodified
8.End Function
9. Sub Check4Changes()
10. 'Checks the file FilePath for changes every 120 seconds
11. 'If file has changed, pops up a message box. Stores the
12. 'last modified time in cell M1 of Sheet1
13. Dim LastMod As Date
14. ChDir "Q:\Manufacturing\Equipment\DispatchLogs\logs\7-DES"
15. Const FilePath As String = "Q:\Manufacturing\Equipment\DispatchLogs\logs\7-DES\"I need the Date here".CSV"
16. On Error GoTo ReSchedule
17. LastMod = LastModTime(FilePath)
18. With Worksheets("Sheet1").Range("D1")
19. If IsEmpty(.Value) Then
20. .Value = LastMod
21. GoTo ReSchedule
22. ElseIf .Value < LastMod Then
23. .Value = LastMod
24. 'MsgBox FilePath & " updated.", vbInformation, "Check4Changes"
25. Call QuickKill
26. End If
27. End With
28. ReSchedule:
29. 'Reschedule this same routine to run in Two minutes.
30. NextTime = Now + 2 / 1440
31. Application.StatusBar = "Next check at " & NextTime
32. Application.OnTime NextTime, "Check4Changes"
33.End Sub
34. Sub CancelChecking()
35. Application.OnTime NextTime, "Check4Changes", Schedule:=False
36. Application.StatusBar = False
37.End Sub
38.Sub Import_CSV()
'
39.' Import_CSV Macro
'
'
40. With ActiveSheet.QueryTables.Add(Connection:= _
41. "TEXT;Q:\Manufacturing\Equipment\DispatchLogs\logs\7-DES\"I need the date Here.CSV"", _
42. Destination:=Range("$A$1"))
43. .Name = "14031406"
44. .FieldNames = True
45. .RowNumbers = False
46. .FillAdjacentFormulas = False
47. .PreserveFormatting = True
48. .RefreshOnFileOpen = False
49. .RefreshStyle = xlInsertDeleteCells
50. .SavePassword = False
51. .SaveData = False
52. .AdjustColumnWidth = True
53. .RefreshPeriod = 0
54. .TextFilePromptOnRefresh = False
55. .TextFilePlatform = 437
56. .TextFileStartRow = 1
57. .TextFileParseType = xlDelimited
58. .TextFileTextQualifier = xlTextQualifierDoubleQuote
59. .TextFileConsecutiveDelimiter = False
60. .TextFileTabDelimiter = False
61. .TextFileSemicolonDelimiter = False
62. .TextFileCommaDelimiter = True
63. .TextFileSpaceDelimiter = False
64. .TextFileColumnDataTypes = Array(3, 2, 1)
65. .TextFileTrailingMinusNumbers = True
66. .Refresh BackgroundQuery:=False
67.End With
68.Call Check4Changes
69.End Sub
Bookmarks