Lotus Cars
Board Regular
- Joined
- Feb 4, 2011
- Messages
- 55
Hi all,
I've got a bit of code to check if a folder is there before saving a file into it. Basically, I want to know if the period folder is there, and if it is, if a subfolder called Final P&L Reports is there. If either or both of the folders are not there, then create it.
It seems to work great if the folders are not there, but if either already exists, it just crashes out. Can anyone help please?
Cheers,
Lotus Cars
' Check folder is there, and if not, then create
If Period = 1 Then accountperiod = "P01"
If Period = 2 Then accountperiod = "P02"
If Period = 3 Then accountperiod = "P03"
If Period = 4 Then accountperiod = "P04"
If Period = 5 Then accountperiod = "P05"
If Period = 6 Then accountperiod = "P06"
If Period = 7 Then accountperiod = "P07"
If Period = 8 Then accountperiod = "P08"
If Period = 9 Then accountperiod = "P09"
If Period = 10 Then accountperiod = "P10"
If Period = 11 Then accountperiod = "P11"
If Period = 12 Then accountperiod = "P12"
If IsFileThere1("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod) Then ActiveCell.Select
Else
MkDir "I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod
End If
If IsFileThere2("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod & "\Final P&L & Reports") Then ActiveCell.Select
Else
MkDir "I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod & "\Final P&L & Reports\"
End If
Public Function IsFileThere1(FileName As String) As Boolean
If Len(Dir("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod)) > 0 Then
IsFileThere = True
Else
IsFileThere = False
End If
End Function
Public Function IsFileThere2(FileName As String) As Boolean
If Len(Dir("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod & "\Final P&L & Reports")) > 0 Then
IsFileThere = True
Else
IsFileThere = False
End If
End Function
I've got a bit of code to check if a folder is there before saving a file into it. Basically, I want to know if the period folder is there, and if it is, if a subfolder called Final P&L Reports is there. If either or both of the folders are not there, then create it.
It seems to work great if the folders are not there, but if either already exists, it just crashes out. Can anyone help please?
Cheers,
Lotus Cars
' Check folder is there, and if not, then create
If Period = 1 Then accountperiod = "P01"
If Period = 2 Then accountperiod = "P02"
If Period = 3 Then accountperiod = "P03"
If Period = 4 Then accountperiod = "P04"
If Period = 5 Then accountperiod = "P05"
If Period = 6 Then accountperiod = "P06"
If Period = 7 Then accountperiod = "P07"
If Period = 8 Then accountperiod = "P08"
If Period = 9 Then accountperiod = "P09"
If Period = 10 Then accountperiod = "P10"
If Period = 11 Then accountperiod = "P11"
If Period = 12 Then accountperiod = "P12"
If IsFileThere1("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod) Then ActiveCell.Select
Else
MkDir "I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod
End If
If IsFileThere2("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod & "\Final P&L & Reports") Then ActiveCell.Select
Else
MkDir "I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod & "\Final P&L & Reports\"
End If
Public Function IsFileThere1(FileName As String) As Boolean
If Len(Dir("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod)) > 0 Then
IsFileThere = True
Else
IsFileThere = False
End If
End Function
Public Function IsFileThere2(FileName As String) As Boolean
If Len(Dir("I:\Accts Cars\Cars Man Accounts 11-12\" & accountperiod & "\Final P&L & Reports")) > 0 Then
IsFileThere = True
Else
IsFileThere = False
End If
End Function