Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I must be reading the following incorrectly.
As it is now written, it processess as if the file exists, even when it doesn't. Last week I had something similar and it always processed as if NO file existed, even when it did. What am I missing here? Sub CheckFileName() Dim FName As String FName = ActiveWorkbook.Name Dim NewName As String NewName = FName & "_EM" ' Check if the following exists: ' C:\Contracts EMailed\'filename'_EM.xls If Dir("C:\Contracts EMailed\" & NewName) = "" Then ' IF it exists, then Process is not allowed ' NotAllowed Message pops up, Click OK, and project Exits Call NotAllowed ' If it does NOT exist, then Exit this code and Continue Else: Exit Sub End If End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Shouldn't it be
Sub CheckFileName() Dim FName As String FName = ActiveWorkbook.Name Dim NewName As String NewName = FName & "_EM" ' Check if the following exists: ' C:\Contracts EMailed\'filename'_EM.xls If Dir("C:\Contracts EMailed\" & NewName) < "" Then ' IF it exists, then Process is not allowed ' NotAllowed Message pops up, Click OK, and project Exits Call NotAllowed ' If it does NOT exist, then Exit this code and Continue Else: Exit Sub End If End Sub -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "BEEJAY" wrote in message ... I must be reading the following incorrectly. As it is now written, it processess as if the file exists, even when it doesn't. Last week I had something similar and it always processed as if NO file existed, even when it did. What am I missing here? Sub CheckFileName() Dim FName As String FName = ActiveWorkbook.Name Dim NewName As String NewName = FName & "_EM" ' Check if the following exists: ' C:\Contracts EMailed\'filename'_EM.xls If Dir("C:\Contracts EMailed\" & NewName) = "" Then ' IF it exists, then Process is not allowed ' NotAllowed Message pops up, Click OK, and project Exits Call NotAllowed ' If it does NOT exist, then Exit this code and Continue Else: Exit Sub End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
File Exists | Excel Discussion (Misc queries) | |||
If a file exists then do this... | Excel Programming | |||
File Exists | Excel Programming | |||
IF File Exists | Excel Programming | |||
the file already exists - do you want to replace the existing file? | Excel Programming |