I have code that pulls .csv documents together into a single workbook and edit a few minor things. It creates a workbook, shuffles in the files from a "Staging Folder" and then autofits/hides some columns/makes row 1 bold.
The .csv's are an output from a Python program, and it can range anywhere from 1-8 files. Each of the eight files will have a unique name that will remain constant with every output.
For Example:
Geometry Errors will ALWAYS give an output named Geometry Errors.
The output will always have some combination of the eight files depending on the errors found.
If I don't have all eight files, then the code doesn't work correctly.
It looks in the staging folder named "DVIEW Staging" and if it doesn't find the file I have the On Error Resume Next
line.
Application.DisplayAlerts = False
Set newbook = Workbooks.Add
ActiveWorkbook.SaveAs Filename:=Aname & "DVIEW Outputs.xlsx"
Environ ("USERPROFILE") + "\DVIEW Staging"
On Error Resume Next
Workbooks.Open Filename:= _
Environ("USERPROFILE") & "\Desktop\DVIEW Staging\Geometry_Errors_Table.csv"
On Error Resume Next
Sheets("Geometry_Errors_Table").Move After:=Workbooks("DVIEW Outputs.xlsx").Sheets(1)
Columns("A:Z").EntireColumn.AutoFit
Range("A:A,B:B,C:C,I:I,J:J,K:K,L:L").Select
Selection.EntireColumn.Hidden = True
Rows("1:1").Select
Selection.Font.Bold = True
Range("D1").Select
On Error Resume Next
Workbooks.Open Filename:= _
Environ("USERPROFILE") & "\Desktop\DVIEW Staging\Fiber_and_Splice_Relationship_Errors.csv"
On Error Resume Next
Sheets("Fiber_and_Splice_Relationship_E").Move After:=Workbooks("DVIEW Outputs.xlsx").Sheets(1)
Columns("A:Z").EntireColumn.AutoFit
Range("A:A,C:C").Select
Selection.EntireColumn.Hidden = True
Rows("1:1").Select
Selection.Font.Bold = True
Range("B1").Select
On Error Resume Next
So when it can't find it, it runs all of the hiding and autofit commands on the CURRENT sheet (one that it found). Meaning if there is one sheet is in the output folder, it could potentially run the autofit/hide/bold seven other times.
How do I block off a section of code to skip if it can't find the document?
I want the block of code beneath the file search to run on THAT file, or not run at all.
I don't want the Geometry Errors block of code to hide seven columns on the Fiber_and_Splice_Relationship_Errors sheet, and then run the Fiber_and_Splice_Relationship_Errors commands after that (because I only want the two columns hidden for that one).