Excel Code
Excel Code
Dim fs As Object
Dim lastInspectionDate As Date ' Added variable for Last Inspection Date
Set fs = CreateObject("Scripting.FileSystemObject")
' Open the master workbook and set the target worksheet
Set masterWB = Workbooks("Non-Insulated Piping Inspection Master Sheet.xlsx") ' Ensure the
master workbook is open
Set masterWS = masterWB.Sheets("Piping Inspection Master Sheet") ' Ensure this sheet exists
targetRow = 3
' Loop through each folder in the parent folder
If folder.Name Like "HP-*" Then ' Process only subfolders like HP-0, HP-1, etc.
Debug.Print "Processing file: " & file.Path ' Log the file being processed
On Error GoTo 0
GoTo NextFile
End If
On Error GoTo 0
' Add a hyperlink to the Drawing No. (assumes PDF file is in the same folder)
masterWS.Hyperlinks.Add _
Anchor:=masterWS.Cells(targetRow, 6), _
Address:=pdfFilePath, _
Else
Debug.Print "Sheet 'Pipe Line Data' not found in: " & file.Path
End If
Else
Debug.Print "Sheet 'Maintenance Activities' not found in: " & file.Path
End If
' Find the last column with data in row 10 starting from column H
' Column K: Max Corrosion Rate (Find max value between columns 5 and 6 of the
target column)
If lastCol >= 8 Then ' Check if columns H, I, J, K have data
maxCorrosionRate = Application.WorksheetFunction.Max(sourceWS.Cells(5,
lastCol).Value, sourceWS.Cells(6, lastCol).Value)
End If
If lastCol >= 8 Then ' Check if there are enough columns to get the next inspection
date
End If
If lastCol >= 8 Then ' Ensure there is data in the last column
End If
Else
Debug.Print "Sheet 'CML READING' not found in: " & file.Path
End If
targetRow = targetRow + 1
sourceWB.Close SaveChanges:=False
End If
NextFile:
Next file
Next pipingFolder
Next subFolder
End If
Next folder
End Sub
Dim ws As Worksheet
Set ws = wb.Sheets(sheetName)
On Error GoTo 0
End Function