ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search for active file name (modified), then.... (https://www.excelbanter.com/excel-programming/375236-search-active-file-name-modified-then.html)

BEEJAY

Search for active file name (modified), then....
 
When a file has been E-Mailed with my code, it is saved as
C:\Contracts EMailed\'Current file name' + _EM.
IF one tries to resave the original file, this code is to check
if it has been saved before.
If YES, then, exit, if NO, continue.

Sub CheckFileName()
' Check if the following exists:
' C:\Contracts EMailed\'filename'_EM.xls
' IF it exists, then Process is not allowed
' NotAllowed Message pops up, Click OK, and project Exits
' If it does NOT exist, then Continue

Dim FName As String
FName = ActiveWorkbook.Name
Dim NewName As String
NewName = FName + "_EM"

' The following line comes up with Compile Error - Syntax error

If "C:\Contracts EMailed\NewName.Exists = True Then

Call NotAllowed

Else: Exit Sub
End If
End Sub

Bob Phillips

Search for active file name (modified), then....
 
Sub CheckFileName()
' Check if the following exists:
' C:\Contracts EMailed\'filename'_EM.xls
' IF it exists, then Process is not allowed
' NotAllowed Message pops up, Click OK, and project Exits
' If it does NOT exist, then Continue

Dim FName As String
FName = ActiveWorkbook.Name
Dim NewName As String
NewName = FName + "_EM"

' The following line comes up with Compile Error - Syntax error

If Dir("C:\Contracts EMailed\" & NewName) = "" Then

Call NotAllowed

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
...
When a file has been E-Mailed with my code, it is saved as
C:\Contracts EMailed\'Current file name' + _EM.
IF one tries to resave the original file, this code is to check
if it has been saved before.
If YES, then, exit, if NO, continue.

Sub CheckFileName()
' Check if the following exists:
' C:\Contracts EMailed\'filename'_EM.xls
' IF it exists, then Process is not allowed
' NotAllowed Message pops up, Click OK, and project Exits
' If it does NOT exist, then Continue

Dim FName As String
FName = ActiveWorkbook.Name
Dim NewName As String
NewName = FName + "_EM"

' The following line comes up with Compile Error - Syntax error

If "C:\Contracts EMailed\NewName.Exists = True Then

Call NotAllowed

Else: Exit Sub
End If
End Sub




BEEJAY

Search for active file name (modified), then....
 
Bob:
Thanks for the prompt response.
I am having some difficulty with the process.
It exits when the file exists - That is Correct
It also exits when the file does NOT exist - Thats when it SHOULD go thru
the complete code.
In case my eye-sight was bad, I also tried a cut and paste from your message.
Same result.
In case it may help, I show below the message that (should only) come up
when the file does exist.

Sub NotAllowed()
Dim Msg As String, Title As String
Dim Config As Integer, ans As Integer
Msg = " This process may NOT be used on an "
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & " 'E-Mail Safe' File"
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & " Please click on OK"
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & " You will be exited from this procedure"
Msg = Msg & vbNewLine & vbNewLine
Config = vbOKOnly = vbExclamation
ans = MsgBox(Msg, Config, Title)

If ans = vbOK Then ActiveWorkbook.Close: End
End Sub

"Bob Phillips" wrote:

Sub CheckFileName()
' Check if the following exists:
' C:\Contracts EMailed\'filename'_EM.xls
' IF it exists, then Process is not allowed
' NotAllowed Message pops up, Click OK, and project Exits
' If it does NOT exist, then Continue

Dim FName As String
FName = ActiveWorkbook.Name
Dim NewName As String
NewName = FName + "_EM"

' The following line comes up with Compile Error - Syntax error

If Dir("C:\Contracts EMailed\" & NewName) = "" Then

Call NotAllowed

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
...
When a file has been E-Mailed with my code, it is saved as
C:\Contracts EMailed\'Current file name' + _EM.
IF one tries to resave the original file, this code is to check
if it has been saved before.
If YES, then, exit, if NO, continue.

Sub CheckFileName()
' Check if the following exists:
' C:\Contracts EMailed\'filename'_EM.xls
' IF it exists, then Process is not allowed
' NotAllowed Message pops up, Click OK, and project Exits
' If it does NOT exist, then Continue

Dim FName As String
FName = ActiveWorkbook.Name
Dim NewName As String
NewName = FName + "_EM"

' The following line comes up with Compile Error - Syntax error

If "C:\Contracts EMailed\NewName.Exists = True Then

Call NotAllowed

Else: Exit Sub
End If
End Sub






All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com