Hi All,
First I would like to say I am blown away by the support and learning I have received since I joined thank you!
Second I had this running until today I received the error
Original code below this Structure That worked until a user loaded a File name 293 characters Long as they are grouping Multi like "Items codes" together for One Photo.
the procedure runs through Codes in Column A "the New name to rename Jpeg Files" once it has found a match in Column D Color text Green, if not color text Red.
My Second Attempt to use "Scripting.FileSystemObject" as i have researched it is a better way of handling the "Dir(FolderPath & File.Value" but I am having issues to get this working correctly.
the line " m = Len(myFile) = ".*" m I have assigned as Integer when debugging I can see the values in Len(myFile) but when I check M = 0 I can't get the value to pass ?
as always your Guidance is most appreciated
thanks Peter
First I would like to say I am blown away by the support and learning I have received since I joined thank you!
Second I had this running until today I received the error
Original code below this Structure That worked until a user loaded a File name 293 characters Long as they are grouping Multi like "Items codes" together for One Photo.
the procedure runs through Codes in Column A "the New name to rename Jpeg Files" once it has found a match in Column D Color text Green, if not color text Red.
Code:
Sub CommandButton1_Click()
Dim FolderPath As String
Dim rng As Range, File As Range
Dim m As Integer
Dim LR As Long
Dim ws As Worksheet
' Dim FolderName As String
'search worksheet change name as required
Set ws = Worksheets("Sheet1") '
'specify search folder FROM FUNCTION above function is a value like a global varible
FolderPath = sItem
'check folder exists
If Dir(FolderPath, vbDirectory) <> vbNullString Then
'last record in column A
LR = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'set the search ranges
Set rng = Union(ws.Range("A2:A" & LR), ws.Range("C2:C" & LR))
For Each File In rng
'check if file Name in range (without file ext) exists in folder and add if Column H has extra repetative text after main column C word
m = Len(Dir(FolderPath & File.Value & ".*"))' ########### Debug Error Here on this line
'change cell font colorindex based on result of m
ws.Cells(File.Row, File.Column).Font.ColorIndex = IIf(m = 0, 3, xlAutomatic)
' ws.Cells(File.Row, File.Column).Font.ColorIndex = IIf(m <> 0, 10, xlAutomatic)
Next File
Else
'tell user folder not found
MsgBox FolderPath & Chr(10) & "Folder Path Not Found", 16, "Not Found"
End If
Call ReName2
End Sub
My Second Attempt to use "Scripting.FileSystemObject" as i have researched it is a better way of handling the "Dir(FolderPath & File.Value" but I am having issues to get this working correctly.
the line " m = Len(myFile) = ".*" m I have assigned as Integer when debugging I can see the values in Len(myFile) but when I check M = 0 I can't get the value to pass ?
as always your Guidance is most appreciated
thanks Peter
Code:
Private Sub CommandButton1_Click()
With Worksheets("Sheet1")
.Unprotect Password:="topsecret"
'Sub ReName()
Dim FolderPath 'As String
Dim m As Integer
Dim LR As Long
Dim ws As Worksheet
Dim fso As Object
Dim fPath As String
Dim myFolder, myFile
Set fso = CreateObject("Scripting.FileSystemObject")
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then fPath = .SelectedItems(1) & "\"
End With
Set myFolder = fso.GetFolder(fPath).Files
For Each myFile In myFolder
'check if file Name in range (without file ext) exists in folder
'm = Len(Dir(FolderPath & File.Value & ".*"))
m = Len(myFile) = ".*"
If LCase(myFile) Like ".*" Then
'If File exists Color Green else Red
Select Case m
Case Is = 0
ws.Cells(File.Row, File.Column).Font.ColorIndex = 3
Case Is > 0
ws.Cells(File.Row, File.Column).Font.ColorIndex = 10
Case Else
ws.Cells(File.Row, File.Column).Font.ColorIndex = xlAutomatic
End Select
End If
Next myFile
'check if file Name in range (without file ext) exists in folder
' m = Len(Dir(FolderPath & File.Value & ".*"))
'tell user folder not found
' MsgBox FolderPath & Chr(10) & "Folder Path Not Found", 16, "Not Found"
End With
Call ReName2
End Sub