I wrote this awhile ago but it still works. It changes all xref and image paths from full path to relative path on the current drawing or on all the drawings in the current drawings folder. Let me know how it works for you.
Code:
Sub Runsall()
Dim cmd As String
Dim cmd2 As String
cmd = ThisDrawing.Utility.GetString(False, "You are about to update all of the Xref and image paths from hard paths to relative paths. Would you like to continue?: Y/N: ")
If UCase(cmd) <> "Y" Then
Exit Sub
End If
cmd2 = ThisDrawing.Utility.GetString(False, "Would you like to run this on the entire directory or the current drawing? D/C : ")
If UCase(cmd2) = "D" Then
direct
ElseIf UCase(cmd2) = "C" Then
xrefpth
End If
End Sub
Sub xrefpth()
Dim a As Integer
Dim l As Integer
Dim c As Integer
Dim D As Integer
Dim i As Integer
Dim pth As String
Dim npath As String
Dim newstr As String
Dim tmpstr As String
Dim xref As AcadExternalReference
Dim ent As AcadEntity
Dim img As AcadRasterImage
Dim blkref As AcadBlockReference
On Error Resume Next
'Loop through the drawing and fid
For i = 0 To ThisDrawing.ModelSpace.Count
If ThisDrawing.ModelSpace.Item(i).ObjectName = "AcDbBlockReference" Then
Set xref = ThisDrawing.ModelSpace.Item(i)
pth = xref.Path
l = Len(pth)
For a = 1 To l
tmpstr = Mid(pth, a, 1)
If tmpstr = "\" Then
D = c
c = a
End If
Next a
newstr = Mid(pth, D)
npth = ".." & newstr
xref.Path = npth
'End If
ElseIf ThisDrawing.ModelSpace.Item(i) = "AcDbRasterImage" Then
Set img = ThisDrawing.ModelSpace.Item(i)
pth = img.ImageFile
l = Len(pth)
For a = 1 To l
tmpstr = Mid(pth, a, 1)
If tmpstr = "\" Then
D = c
c = a
End If
Next a
newstr = Mid(pth, D)
npth = ".." & newstr
img.ImageFile = npth
End If
npth = ""
pth = ""
Next i
End Sub
Sub direct()
Dim doc As AcadDocument
Dim docs As AcadDocuments
' Get the directory of the current drawing
MyPath = (ThisDrawing.Path) & "\*.dwg" ' Set the path.
MyName = Dir(MyPath, vbNormal)
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' check if document is already open
If Not MyName = ThisDrawing.Application.ActiveDocument.Name Then
ThisDrawing.Application.Documents.Open (ThisDrawing.Path & "\" & MyName)
End If
'run the xref routine
xrefpth
'close drawing as long as 1 drawing is always open
If ThisDrawing.Application.Documents.Count > 1 Then
ThisDrawing.Application.ActiveDocument.Close
End If
End If
MyName = Dir ' Get next entry.
Loop
End Sub