HI there, I am a complete novice in excel and get by by scavenging code off of forums and playing with them until i get them to work.I have how ever hit a wall. The following code works as a macro assigned to a button, but when i place it in the *This workbook page so the macro is run on start up i get the compiler error,*User-defined type not defined*I would very much appreciate some help and some advice on what i am doing wrong. Thank you https://www.mrexcel.com/forum/images/smilies/icon_nya.gifPrivate Sub Workbook_Open()Dim fdr, fdr2 As Scripting.Folder Dim target As Scripting.File For Each fdr In CreateObject("Scripting.FileSystemObject").GetFolder("S:\Systems Eng\Rolling Stock\MCU\Reports\Today's in service plan's\2018").SubFolders On Error Resume Next For Each target In fdr.Files If InStr(1, UCase(target), UCase(".xls")) > 0 Then If target.DateLastModified > dteFile Then dteFile = target.DateLastModified strFile = target End If End If Next Next DateFirstFile = dteFile FirstFile = strFile For Each fdr2 In CreateObject("Scripting.FileSystemObject").GetFolder("S:\Systems Eng\Rolling Stock\MCU\Reports\Today's in service plan's\2018").SubFolders On Error Resume Next For Each target In fdr2.Files If InStr(1, UCase(target), UCase(".xls")) > 0 Then If target.DateLastModified > dteFile Then dteFile = target.DateLastModified strFile = target End If End If Next Next DateSecondFile = dteFile SecondFile = strFile If DateFirstFile >= DateSecondFile Then If Len(Dir(FirstFile)) Then Workbooks.Open FirstFile ElseIf DateSecondFile >= DateFirstFile Then If Len(Dir(SecondFile)) Then Workbooks.Open SecondFile End IfEnd Sub