The code below searches alll the VBA code in my workbook for refrence to "G:\Shared…
- User
The code below searches alll the VBA code in my workbook for refrence to "G:\Shared drives". The code is accurate and works very well. Can you write a similar code that doe the following:
Omitting the sheet VBA, search all formulas in the sheet cells for links to all external files outside of the Workbook.
Sub SearchVBALinkedDocs() 'SEARCHES VBA OF ALL SHEETS FOR LINK PATH TO G Dim wb As Workbook Dim linkedDocsWs As Worksheet Dim lastRow As Long Dim ws As Worksheet Dim moduleCode As String Dim addressPath As String Dim lineIndex As Long Dim startPos As Long Dim endPos As Long Set wb = ThisWorkbook Set linkedDocsWs = wb.Sheets("Linked Docs") For Each ws In wb.Sheets On Error Resume Next lineIndex = 1 ' Check if the sheet has a code module If ws.Type = xlWorksheet Then ' Get the module code of the sheet moduleCode = wb.VBProject.VBComponents(ws.CodeName).codeModule.Lines(1, wb.VBProject.VBComponents(ws.CodeName).codeModule.CountOfLines) startPos = InStr(1, moduleCode, "G:\Shared drives") Do Until startPos = 0 endPos = InStr(startPos, moduleCode, """") If endPos > startPos Then addressPath = Mid(moduleCode, startPos, endPos - startPos) lastRow = linkedDocsWs.Cells(linkedDocsWs.Rows.Count, "D").End(xlUp).Row + 1 linkedDocsWs.Cells(lastRow, "D").Value = addressPath linkedDocsWs.Cells(lastRow, "E").Value = "'" & ws.Name End If startPos = InStr(startPos + 1, moduleCode, "G:\Shared drives") Loop End If On Error GoTo 0 Next ws Call Module32.SearchMODLinkedDocs End Sub
- Assistant
Here is a similar code that searches all formulas in the sheet cells for links to external files outside of the workbook:
Sub SearchFormulaLinkedDocs() ' SEARCHES FORMULAS OF ALL SHEETS FOR EXTERNAL FILE LINKS Dim wb As Workbook Dim linkedDocsWs As Worksheet Dim lastRow As Long Dim ws As Worksheet Dim cell As Range Dim formula As String Dim startPos As Long Dim endPos As Long Set wb = ThisWorkbook Set linkedDocsWs = wb.Sheets("Linked Docs") For Each ws In wb.Sheets For Each cell In ws.UsedRange On Error Resume Next ' Check if the cell contains a formula If cell.HasFormula Then formula = cell.Formula startPos = InStr(1, formula, "='G:\Shared drives") Do Until startPos = 0 endPos = InStr(startPos, formula, "'") If endPos > startPos Then addressPath = Mid(formula, startPos, endPos - startPos) lastRow = linkedDocsWs.Cells(linkedDocsWs.Rows.Count, "D").End(xlUp).Row + 1 linkedDocsWs.Cells(lastRow, "D").Value = addressPath linkedDocsWs.Cells(lastRow, "E").Value = "'" & ws.Name End If startPos = InStr(startPos + 1, formula, "='G:\Shared drives") Loop End If On Error GoTo 0 Next cell Next ws Call Module32.SearchMODLinkedDocs End Sub
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.