Dummy Excel
Well-known Member
- Joined
- Sep 21, 2005
- Messages
- 1,004
- Office Version
- 2019
- 2010
- 2007
- Platform
- Windows
Hi All,
im trying to open 2 spreadsheets one after the other. my code is:
can someone tell me where im going wrong?
thanks in advance
Sam
im trying to open 2 spreadsheets one after the other. my code is:
Code:
Sub OpenFile(customer)
If customer = "abc x" Or customer = "cde" Or customer = "zzz" Or customer = "ww" Then
Workbooks.Open GetFile("S:\Workwear\")
Else
If customer = "123" Then
Workbooks.Open GetFile("S:\Workwear\")
Else
If customer = "456" Then
Workbooks.Open GetFile("S:\Workwear\")
Else
If customer = "789" Then
Workbooks.Open GetFile("S:\Workwear\")
Else
If customer = "012" Then
Workbooks.Open GetFile("S:\Workwear\")
End If
End If
End If
End If
End If
End Sub
Function GetFile(Path As String) As String
Dim f As Object, d As Date, fname1 As String, fname2 As String, loc1 As String, loc2 As String
If customer = "abc x" Or customer = "cde" Or customer = "zzz" Or customer = "ww" Then
fname1 = customer & " " & Business1 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
fname2 = customer & " " & Business2 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
loc1 = "S:\Workwear\" & fname1
loc2 = "S:\Workwear\" & fname2
Else
If customer = "123" Then
fname1 = customer & " " & Business1 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
fname2 = customer & " " & Business2 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
loc1 = "S:\Workwear\" & fname1
loc2 = "S:\Workwear\" & fname2
Else
If customer = "456" Then
fname1 = customer & " " & Business1 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
fname2 = customer & " " & Business2 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
loc1 = "S:\Workwear\" & fname1
loc2 = "S:\Workwear\" & fname2
Else
If customer = "789" Then
fname1 = customer & " " & Business1 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
fname2 = customer & " " & Business2 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
loc1 = "S:\Workwear\" & fname1
loc2 = "S:\Workwear\" & fname2
Else
If customer = "012" Then
fname1 = customer & " " & Business1 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
fname2 = customer & " " & Business2 & " OF " & WorksheetFunction.Proper(format(DateSerial(Year(Now), Month(Now) - 2, Day(Now)), "MMM yy")) & ".xls"
loc1 = "S:\Workwear\" & fname1
loc2 = "S:\Workwear\" & fname2
End If
End If
End If
End If
End If
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(Path).Files
If f = loc1 Then
If d < f.DateLastModified Then
d = f.DateLastModified
GetFile = f.Path
End If
End If
Next
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(Path).Files
If f = loc2 Then
If d < f.DateLastModified Then
d = f.DateLastModified
GetFile = f.Path
End If
End If
Next
end function
thanks in advance
Sam