Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What wrong is this macro? Referring to following code, I don\'t understand why F

ID: 3565665 • Letter: W

Question

What wrong is this macro?

Referring to following code, I don't understand why Formula 2 works, but not Formula 1.

Does anyone have any suggestions?
Thanks in advance for any suggestions

Sub CheckFile()
Dim FilePath As String

FilePath = "='D:ABC..xls"
If FileExists(FilePath) Then Range("A1") = True Else Range("A1") = False ' Formula 1

If FileExists("D:ABC.xls") Then Range("A1") = True Else Range("A1") = False ' Formula 2

End Sub

Public Function FileExists(ByVal Filename As String) As Boolean
     Dim nAttr As Long
     On Error GoTo NoFile
     nAttr = GetAttr((Filename))
     If (nAttr And vbDirectory)) <> vbDirectory Then
        FileExists = True
     End If
NoFile:
End Function

Explanation / Answer

Hi

Change:

FilePath = "='D:ABC.xls"

to:

FilePath = ""D:ABC.xxls""

Note the removal of the single quote and equals sign before !!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote