cdbrown
07-07-2006, 01:33 AM
Hi all,
I'm using the following code to check if a folder exists and if not create it. I'm recording the folder name in a cell and referencing that but it always defaults to False in the Function section
Function ChkFolderExists(strFolder As String) As Boolean
On Error GoTo ErrHandler:
If Dir(strFolder) <> "" Then
ChkFolderExists = True
Else
ChkFolderExists = False
End If
Exit Function
ErrHandler:
ChkFolderExists = False
End Function
Set wb1 = ThisWorkbook
Sheets("List").Select
SaveFolder = Cells(3, 6)
Cells(14, 6).Value = SaveFolder & "\Consequences\"
Folder = CStr(Cells(14, 6))
If ChkFolderExists(Folder) = False Then
MkDir Cells(14, 6)
End If
Rows = Sheets("Relat").Cells(8, 3)
When stepping through the macro I put the mouse over the strFolder and it returns
strFolder="K:\Test\Consequences\"
The folder exists and as it comes up false it tries to make the directory which causes an error. I have tried it both with the folder there and without and it always returns a false - any ideas? This loop works fine in a different macro.
Cheers
-cdbrown
I'm using the following code to check if a folder exists and if not create it. I'm recording the folder name in a cell and referencing that but it always defaults to False in the Function section
Function ChkFolderExists(strFolder As String) As Boolean
On Error GoTo ErrHandler:
If Dir(strFolder) <> "" Then
ChkFolderExists = True
Else
ChkFolderExists = False
End If
Exit Function
ErrHandler:
ChkFolderExists = False
End Function
Set wb1 = ThisWorkbook
Sheets("List").Select
SaveFolder = Cells(3, 6)
Cells(14, 6).Value = SaveFolder & "\Consequences\"
Folder = CStr(Cells(14, 6))
If ChkFolderExists(Folder) = False Then
MkDir Cells(14, 6)
End If
Rows = Sheets("Relat").Cells(8, 3)
When stepping through the macro I put the mouse over the strFolder and it returns
strFolder="K:\Test\Consequences\"
The folder exists and as it comes up false it tries to make the directory which causes an error. I have tried it both with the folder there and without and it always returns a false - any ideas? This loop works fine in a different macro.
Cheers
-cdbrown