Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

 

Or maybe the issue is the code is attempting to rename an occurrence the same name as another occurrence... maybe something like this to catch that case.

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
i=1
FilePrefix = "Test_"
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
   	Dim oName As String 
   	oName = oOccurrence.Name
	oName2 = Left(oName, 1)
	oName3 = Left(oName, 3)
	oName4 = Mid(oName, 4)
	
	If oName2 = "-" Then 
		oOccurrence.Name = FilePrefix & oName
	Else If oName3 <> FilePrefix Then
		Try
		oOccurrence.Name = FilePrefix & oName4
		Catch 'error when name exists already
		oOccurrence.Name = FilePrefix & oName4 & ":" & i
		i=i+1 'increment counter
		End Try
	End If

Next