Hi! Sorry if my formatting is incorrect, I haven't posted here before.
Edit: I am very new to VBA, by the way!
I have a column of part numbers and I'm working on filling out columns of info about that part. Some of this info comes from SolidWorks drawings which are contained in a .dwg file.
This is the code I found to check if the file exists that equals the cell value.
Sub CheckIfFileExists()
Dim LRow As Integer
Dim LPath As String
Dim LExtension As String
Dim LContinue As Boolean
'Initialize variables
LContinue = True
LRow = 2
LPath = "C:\Users\myname\Desktop\"
LExtension = ".txt"
'Loop through all column A values until a blank cell is found
While LContinue
'Found a blank cell, do not continue
If Len(Range("A" & CStr(LRow)).Value) = 0 Then
LContinue = False
'Check if file exists for part number
Else
'Place "No" in column B if the file does NOT exist
If Len(Dir(LPath & Range("A" & CStr(LRow)).Value & LExtension)) = 0 Then
Range("B" & CStr(LRow)).Value = "No"
'Place "Yes" in column B if the file does exist
Else
Range("B" & CStr(LRow)).Value = "Yes"
End If
End If
LRow = LRow + 1
Wend
End Sub
If I have "Hello" in a cell, and "Hello.txt" on my desktop, it returns Yes which is great; however, the .dwg files would probably show up like "3123Hello3295889.dwg," which, obviously, returns no. Is there any way to check if a filename CONTAINS the cell value instead?
Bookmarks