Yes, changing sheet selection is an issue, and unnecessary. You can avoid it
Sub CheckFiles()
'Sub Auto_Open() 'If you want to run at open
'Application.ScreenUpdating = False
'20171217
'
'Runs automatically when file opened
'Colours Directories yellow if they do not exist
'Colours files names yellow if they do not exist
'Removes colour if the file exists
'
'--------------------Dimensions---------------------
Dim Str01 As String, Str02 As String
Dim Rng01 As Range, Rng02 As Range, Rng03 As Range, Rng04 As Range
Dim Cell As Range
Dim objFSO As Object
Dim objFolder As Object
Dim objFSO01 As Object
Dim objFolder01 As Object
'--------------------Dimensions---------------------
'---------------------Variables---------------------
Str01 = "Document Numbering"
'Directory_Location = Named Group
'File_Name = Named Group of the file
'---------------------Variables---------------------
'-----------------------A0000-----------------------
'Gathers the list of directorys stated within this document
Set Rng01 = ThisWorkbook.Sheets(Str01).Range("Directory_Location").Offset(1, 0)
Call Functions_Module.BlanksToSkip(Rng01, "d", Rng02, 4)
'-----------------------A0000-----------------------
'-----------------------A0001-----------------------
' goes through the directories an sees if any are missing
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO01 = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
For Each Cell In Sheets(Str01).Range(Rng01, Rng02)
Set objFolder = objFSO.GetFolder(Cell.Value)
If Err.Number <> "0" Then
Cell.Interior.Color = 65535
GoTo line1:
Else
Cell.Interior.ColorIndex = 0
End If
Err.Clear
Str02 = Cell & "\" & Cell.Offset(0, 1)
'Set objFolder01 = objFSO01.GetFile(Cell.Offset(0, 1))
Set objFolder01 = objFSO01.GetFile(Str02)
If Err.Number <> "0" Then
Cell.Offset(0, 1).Interior.Color = 65535
GoTo line1:
Else
Cell.Offset(0, 1).Interior.ThemeColor = xlThemeColorAccent1
Cell.Offset(0, 1).Interior.TintAndShade = 0.799981688894314
'Cell.Offset(0, 1).Interior.ColorIndex = 0
End If
line1:
Err.Clear
Next Cell
'-----------------------A0001-----------------------
'-----------------------A0002-----------------------
'File_Name check to see if correct
End Sub
and
Function BlanksToSkip(x1 As Range, Direction As String, Optional x2 As Range, Optional Blanks As Long)
'Call Functions_Module.BlanksToSkip(x1, "Right",x2, 1)
'x1 is the start of the search, x2 what will be saved as the result. Optional as you may not want to save x2
'Direction must be "up", "down", "left", "right" or "U", "D", "L", "R"
'If 'Blanks' left out, then assumes zero blanks within data column/row.
'
'BlanksToSkip finishes the program with the selected cell being x2.
'
'Breaks if going up and the has a search attached to row 1.
'Breaks if going left and the search is attached to column1.
Dim AAA As String
AAA = ""
Set x2 = x1
If UCase(Direction) = "UP" Or UCase(Direction) = "U" Then: x = 0: Y = -1: AAA = xlUp
If UCase(Direction) = "DOWN" Or UCase(Direction) = "D" Then: x = 0: Y = 1: AAA = xlDown
If UCase(Direction) = "LEFT" Or UCase(Direction) = "L" Then: x = -1: Y = 0: AAA = xlToLeft
If UCase(Direction) = "RIGHT" Or UCase(Direction) = "R" Then: x = 1: Y = 0: AAA = xlToRight
If AAA = "" Or Blank < 0 Then MsgBox ("Error within 'Direction' or Blanks are negative of function BlanksToSkip"): Exit Function
For ii = 1 To Blanks + 1
For i = 1 To Blanks + 1
Do While Not IsEmpty(x2.Offset(i * Y, ii * x))
Set x2 = x2.End(AAA)
i = 1
ii = 1
Loop
Next i
Next ii
End Function
I couldn't really see a need for CallByName in there.
Bookmarks