Just for the sake of completeness you should be aware of the difference
between "" and vbNullString when calling Windows API functions in VBA. In
most cases in VBA, you can use "" and vbNullString interchangeably. For
example,
If X = vbNullString Then
'and
If X = "" Then
will work the same way. However, there is a difference when working with
Windows API functions. Often, the documentation for an function will say
something like "Set this parameter to NULL for some action.". In this case,
you MUST use vbNullString rather than "". An "" is an allocated string in
memory that happens to have a length of 0. vbNullString indicates
unallocated memory. You can see the difference quite clearly with the
unsupported StrPtr function:
Dim S1 As String
Dim S2 As String
S1 = ""
S2 = vbNullString
If S1 = S2 Then
Debug.Print "Their values match, as expected..."
End If
Debug.Print "But their pointers don't: S1: " & CStr(StrPtr(S1)) & _
" S2: " & CStr(StrPtr(S2))
StrPtr(S1) will return some memory address.
StrPtr(S2) will return 0.
When passing null strings to Windows API functions, you MUST use
vbNullString, not "".
The unsupported StrPtr function is useful with the InputBox function. For
example in the following code, you cannot determine whether the user clicked
the OK button with no input text or clicked Cancel:
S1 = InputBox("Enter some text")
If S1 = vbNullString Then
Debug.Print "#1: User clicked Cancel OR clicked OK with no input." & _
"We can't tell the difference."
End If
However, with the StrPtr function, you can determine whether the user
clicked Cancel or clicked OK with no input text.
S1 = InputBox("Enter some text")
If StrPtr(S1) = 0 Then
Debug.Print "#2: User clicked Cancel"
Else
Debug.Print "#2: User clicked OK"
End If
This is all tangential to the original question, but it good info to have at
hand when your programming.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)
"BEEJAY" <(E-Mail Removed)> wrote in message
news:92987BBA-DBD5-453D-B78E-(E-Mail Removed)...
> Have the following (corrected in this newsgroup)
> I don't understand what the double quotes stand for, so I can't
> figure out why my code does not work properly.
>
> If Dir("C:\Contracts EMailed\" & NewName) = "" Then
> I need this line to read:
> If current active file name + _EM exists in C:\Contracts EMailed, Then
> Call NotAllowed (which is a message with an exit statement)
> Else continue.............
> The context is:
> Dim FName As String
> FName = ActiveWorkbook.Name
> Dim NewName As String
> NewName = FName + "_EM"
>
> If Dir("C:\Contracts EMailed\" & NewName) = "" Then
> Call NotAllowed
> Else: Exit Sub
> End If
> End Sub
>