I'm trying to open the latest file in a folder via button macro in access with the following code.
Tested using the if statement and I didn't see any problems. But once I used do while, i receive an error message of run time 6, overflow.
does len(dir())
not work with loops?
Below is my code.
Private Sub Command4_Click()
Dim ~~~~ As Object
Set ~~~~ = CreateObject("Excel.Application")
Dim path As String
Dim name As String
Dim count As Long
Dim number As Long
path = "C:Users~~~~~Desktop~~~~~~~~~~~~"
number = Len(Dir(path & "~~~~~~~ - " & Format(Now() - count, "MMMM dd, yyyy") & ".xlsm"))
Do While number = 0
count = count + 1
Loop
~~~~~.workbooks.Open path & "~~~~~~~ - " & Format(Now() - count, "MMMM dd, yyyy") & ".xlsm"
End Sub
the ~ lines are just placeholders due to confidentiality.
Thank you very much.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…