ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error whil reading file (https://www.excelbanter.com/excel-programming/303682-error-whil-reading-file.html)

Philipp Oberleitner[_2_]

Error whil reading file
 
I try to get the newest .xls file in a directory. Anyone sees why me method
brings up an error and doesnt find the files ? There are files in the ginven
directory.

Public ZMappe As String

Sub Auto_Open()

Dim Dat As Date
Dim DatVgl As Date
Dim Mappe As String

Const s = _
"F:\Siemens"
Mappe = Dir(s & "\*.xls")
Dat = FileDateTime(s & "\" & Mappe)

Do Until Mappe = ""
DatVgl = FileDateTime(s & "\" & Mappe)
If DatVgl Dat Then
Dat = DatVgl
ZMappe = s & "\" & Mappe
End If
Mappe = Dir()
Loop

Workbooks.Open Filename:=ZMappe

End Sub



Tom Ogilvy

Error whil reading file
 
Code worked OK for me.

--
Regards,
Tom Ogilvy


"Philipp Oberleitner" wrote in message
...
I try to get the newest .xls file in a directory. Anyone sees why me

method
brings up an error and doesnt find the files ? There are files in the

ginven
directory.

Public ZMappe As String

Sub Auto_Open()

Dim Dat As Date
Dim DatVgl As Date
Dim Mappe As String

Const s = _
"F:\Siemens"
Mappe = Dir(s & "\*.xls")
Dat = FileDateTime(s & "\" & Mappe)

Do Until Mappe = ""
DatVgl = FileDateTime(s & "\" & Mappe)
If DatVgl Dat Then
Dat = DatVgl
ZMappe = s & "\" & Mappe
End If
Mappe = Dir()
Loop

Workbooks.Open Filename:=ZMappe

End Sub





Philipp Oberleitner[_2_]

Error whil reading file
 
Hmm
dont understand why it brings error


"Tom Ogilvy" schrieb im Newsbeitrag
...
Code worked OK for me.

--
Regards,
Tom Ogilvy


"Philipp Oberleitner" wrote in message
...
I try to get the newest .xls file in a directory. Anyone sees why me

method
brings up an error and doesnt find the files ? There are files in the

ginven
directory.

Public ZMappe As String

Sub Auto_Open()

Dim Dat As Date
Dim DatVgl As Date
Dim Mappe As String

Const s = _
"F:\Siemens"
Mappe = Dir(s & "\*.xls")
Dat = FileDateTime(s & "\" & Mappe)

Do Until Mappe = ""
DatVgl = FileDateTime(s & "\" & Mappe)
If DatVgl Dat Then
Dat = DatVgl
ZMappe = s & "\" & Mappe
End If
Mappe = Dir()
Loop

Workbooks.Open Filename:=ZMappe

End Sub







Dave Peterson[_3_]

Error whil reading file
 
Could it be that the first time through it found the newest--and you didn't keep
track of that first filename?

Option Explicit

Sub Auto_Open()

Dim Dat As Date
Dim DatVgl As Date
Dim Mappe As String
Dim ZMappe As String '<-- added

Const s = _
"c:\temp"
Mappe = Dir(s & "\*.xls")
Dat = FileDateTime(s & "\" & Mappe)

ZMappe = s & "\" & Mappe '<-- added

Do Until Mappe = ""
DatVgl = FileDateTime(s & "\" & Mappe)
If DatVgl Dat Then
Dat = DatVgl
ZMappe = s & "\" & Mappe
End If
Mappe = Dir()
Loop

Workbooks.Open Filename:=ZMappe

End Sub

Philipp Oberleitner wrote:

Hmm
dont understand why it brings error

"Tom Ogilvy" schrieb im Newsbeitrag
...
Code worked OK for me.

--
Regards,
Tom Ogilvy


"Philipp Oberleitner" wrote in message
...
I try to get the newest .xls file in a directory. Anyone sees why me

method
brings up an error and doesnt find the files ? There are files in the

ginven
directory.

Public ZMappe As String

Sub Auto_Open()

Dim Dat As Date
Dim DatVgl As Date
Dim Mappe As String

Const s = _
"F:\Siemens"
Mappe = Dir(s & "\*.xls")
Dat = FileDateTime(s & "\" & Mappe)

Do Until Mappe = ""
DatVgl = FileDateTime(s & "\" & Mappe)
If DatVgl Dat Then
Dat = DatVgl
ZMappe = s & "\" & Mappe
End If
Mappe = Dir()
Loop

Workbooks.Open Filename:=ZMappe

End Sub





--

Dave Peterson



All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com