VBA Help: FileExists with status on Col J

harky

Active Member
Joined
Apr 8, 2010
Messages
405
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hi
I need a smiliar vbs but with Sub, not function which able to update the status on Col J when i activate the macro.

It will left a remarks

Directory & Link Ok
File was not found in folder

The best if can differentiate which one is Folder, which is link :)

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"]H[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[/TR]
[TR]
[TD]
FOLDER Path
[/TD]
[TD]
SINGLE Path
[/TD]
[TD="align: center"]Status[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]C:\Users\ABC\Desktop\SavedFolder\Email1\test.JPG[/TD]
[TD]Link Ok[/TD]
[/TR]
[TR]
[TD]C:\Users\ABC\Desktop\SavedFolder\Email2\[/TD]
[TD][/TD]
[TD]Folder was not found[/TD]
[/TR]
</tbody>[/TABLE]



Code:
Function FileExist(path As String) As Boolean
    If Dir(path) <> vbNullString Then FileExist = True
End Function
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Some non-Dir functions to validate file/folder existence:

Code:
Function FileExists(ByVal FileSpec As String) As Boolean
  ' Karl Peterson MS VB MVP
  Dim Attr As Long
  ' Guard against bad FileSpec by ignoring errors
  ' retrieving its attributes.
  On Error Resume Next
  Attr = GetAttr(FileSpec)
  If Err.number = 0 Then
    ' No error, so something was found.
    ' If Directory attribute set, then not a file.
    FileExists = Not ((Attr And vbDirectory) = vbDirectory)
  End If
End Function

Function DirExists(ByVal FileSpec As String) As Boolean
  ' Karl Peterson MS VB MVP
  Dim Attr As Long
  ' Guard against bad FileSpec by ignoring errors
  ' retrieving its attributes.
  On Error Resume Next
  Attr = GetAttr(FileSpec)
  If Err.number = 0 Then
    ' No error, so something was found.
    ' If Directory attribute set, then not a file.
    DirExists = (Attr And vbDirectory) = vbDirectory
  End If
End Function

Function FSOFolderExists(sFolderName As String) As Boolean
    'With/Without trailing slash works
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    FSOFolderExists = fso.FolderExists(sFolderName)
    Set fso = Nothing

End Function

Function FSOFileExists(sFilePathNameExt As String) As Boolean

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    FSOFileExists = fso.FileExists(sFilePathNameExt)
    Set fso = Nothing

End Function
 
Upvote 0

Forum statistics

Threads
1,223,575
Messages
6,173,148
Members
452,502
Latest member
PQCurious

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top