Rlb53
06-30-2016, 05:51 PM
I'm Checking for an existing file upon opening a ".xlsm" book.
If The File does not exist. I'm creating it.
if the file does exist, I want to bypass the call and continue with code written.
The problem I'm running into is that although the file exists.. the code is still creating and overwriting the existing file.
With the generosity of Ken... if'm using his Function to supplement the action.
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author : Ken Puls (www.excelguru.ca (http://www.excelguru.ca))
'Macro Purpose: Check if a file or folder exists
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
On Error GoTo 0
End Function
In other cases... the Function is performing as intended... but not here for some reason.
With Sheets("Products")
For Each cell In .Range("A:A")
If Not cell.Value = "" Then
If Not cell.Value = "Misc. BOL" Then
If Not cell.Value = "ProductName" Then
If Not FileFolderExists("C:BOLData\DataStorage\" & cell.Value & "InvBkupData.xlsx") Then
Workbooks.Add.SaveAs ("C:BOLData\DataStorage\" & cell.Value & "InvBkupData.xlsx")
Workbooks(cell.Value & "InvBkupData.xlsx").Close
MsgBox ("I've Created Workbook C:BOLData\DataStorage\" & cell.Value & "InvBkupData.xlsx")
End If
End If
End If
End If
Next
End With
What am I not seeing here? Why would the action not recognize that the file folder "DOES" exist and move on?
If The File does not exist. I'm creating it.
if the file does exist, I want to bypass the call and continue with code written.
The problem I'm running into is that although the file exists.. the code is still creating and overwriting the existing file.
With the generosity of Ken... if'm using his Function to supplement the action.
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author : Ken Puls (www.excelguru.ca (http://www.excelguru.ca))
'Macro Purpose: Check if a file or folder exists
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
On Error GoTo 0
End Function
In other cases... the Function is performing as intended... but not here for some reason.
With Sheets("Products")
For Each cell In .Range("A:A")
If Not cell.Value = "" Then
If Not cell.Value = "Misc. BOL" Then
If Not cell.Value = "ProductName" Then
If Not FileFolderExists("C:BOLData\DataStorage\" & cell.Value & "InvBkupData.xlsx") Then
Workbooks.Add.SaveAs ("C:BOLData\DataStorage\" & cell.Value & "InvBkupData.xlsx")
Workbooks(cell.Value & "InvBkupData.xlsx").Close
MsgBox ("I've Created Workbook C:BOLData\DataStorage\" & cell.Value & "InvBkupData.xlsx")
End If
End If
End If
End If
Next
End With
What am I not seeing here? Why would the action not recognize that the file folder "DOES" exist and move on?