I am trying to open the most recent file in a specific folder but when I run the program an error appears and says that the folder does not exist (but it does exist), can someone help me?
Code:
Original Path:
Error:
Translation:
We are sorry but we were unable to locate D: \ Users \ AFCALME \ Documents \ Projeto_Luis \ Andre \ EEC \ QEIM \ QEIM_geral.
Is it possible that it has been moved, deleted or that its name has been changed?
Error Line:
Code:
VBA Code:
Private Sub WriteValues()
Workbooks.Open (myMostRecentFile)
Workbooks(myMostRecentFile).Sheets("QEIM C21").Select
ActiveCell = Range("AC12").Select
If ActiveCell.Value = "" Then
ActiveCell.Select
With Selection
.Name = "Date"
.HorizontalAlignment = xlRight
End With
Range("AD12").Select
With Selection
.Name = "Time"
.HorizontalAlignment = xlRight
End With
Range("AE12").Select
With Selection
.Name = "Value"
End With
Else
End If
Range("AC13").Select
If ActiveCell.Value = "" Then
Call FillCells
Else
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
Call FillCells
End If
End Sub
Sub FillCells()
ActiveCell.Value = Range("C13").Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = WorksheetFunction.Sum(Range("W13:W108"), Range("AA13:AA108"))
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "kWh"
End Sub
Private Sub recentFilesSpecificFolder()
Dim myFile As String, myMostRecentFile As String, myRecentFile As String, myDirectory As String, fileExtension As String
Dim recentDate As Date
myDirectory = Environ("userprofile") & "\Documents\Projeto_Luis\Andre\EEC\QEIM\QEIM_geral"
fileExtension = " * .xls"
If Right(myDirectory, 1) <> "\" Then myDirectory = myDirectory & "\"
myFile = Dir(myDirectory & fileExtension)
If myFile <> "" Then
myRecentFile = myFile
recentDate = FileDateTime(myDirectory & myFile)
Do While myFile <> ""
If FileDateTime(myDirectory & myFile) > recentDate Then
myRecentFile = myFile
recentDate = FileDateTime(myDirectory & myFile)
End If
myFile = Dir
Loop
End If
myMostRecentFile = myRecentFile
Workbooks.Open Filename:=myDirectory & myMostRecentFile
End Sub
Original Path:
Error:
Translation:
We are sorry but we were unable to locate D: \ Users \ AFCALME \ Documents \ Projeto_Luis \ Andre \ EEC \ QEIM \ QEIM_geral.
Is it possible that it has been moved, deleted or that its name has been changed?
Error Line: