能否让VBA宏观公司通过下载文件,以便进口最后(最近的)CSV ?
ChatGPT建议如下。
Sub ImportLastCSVFile()
Dim strPath As String
Dim strFile As String
Dim wb As Workbook
Dim ws As Worksheet
Dim strRawPath As String
Replace with the correct download directory
strRawPath = "C:UsersAlexandreBrandtDownloads"
strPath = strRawPath & "*.csv"
strFile = Dir(strPath, vbNormal)
Find the last CSV file
While Len(strFile) <> 0
If FileDateTime(strRawPath & strFile) > FileDateTime(strRawPath & strPath) Then
strPath = strFile
End If
strFile = Dir() Get next file
Wend
Set the workbook and worksheet
Set wb = ThisWorkbook
On Error Resume Next
Set ws = wb.Sheets("Import")
If Not ws Is Nothing Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
The VBE debugger is not accepting
If FileDateTime(strRawPath & strFile) > FileDateTime(strRawPath & strPath) Then
是否有更好的办法通过档案来写假?