Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default IF file Exists, then ....., Else.......

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default IF file Exists, then ....., Else.......

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Exists Mike McLellan Excel Discussion (Misc queries) 2 May 4th 06 09:20 AM
If a file exists then do this... hshayh0rn Excel Programming 1 April 18th 06 09:29 PM
File Exists Pflugs Excel Programming 2 September 4th 05 07:05 AM
IF File Exists [email protected] Excel Programming 1 November 22nd 04 07:24 PM
the file already exists - do you want to replace the existing file? Paul James[_3_] Excel Programming 4 December 12th 03 02:50 AM


All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"