Here is a macro that reloads the active document if it is a part, or the selected component in the case of an assembly
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swAss As SldWorks.AssemblyDoc
Dim nRetVal As swComponentReloadError_e
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Select Case swModel.GetType
Box swDocumentTypes_e.swDocPART
Set swPart = swModel
swModel.ForceReleaseLocks
nRetVal = swModel.ReloadOrReplace(False, swModel.GetPathName, True)
Box swDocumentTypes_e.swDocASSEMBLY
' We test if a component is selected
Dim blUnSelected As Boolean
Set swAss = swModel
Dim swSelectionMgr As SldWorks.SelectionMgr
Set swSelectionMgr = swModel.SelectionManager
If swSelectionMgr.GetSelectedObjectCount2(0) = 0 Then blUnSelected = True
If swSelectionMgr.GetSelectedObjectType3(1, 0) <> swSelectType_e.swSelCOMPONENTS Then blUnSelected = True
If blUnSelected Then
MsgBox "Please select a component", vbInformation
Exit Sub
End If
' We retrieve the selected component
Dim swComponent As SldWorks.Component2
Set swComponent = swSelectionMgr.GetSelectedObject6(1, 0)
' We recharge it
Dim swDoc As SldWorks.ModelDoc2
Set swDoc = swComponent.GetModelDoc2
swDoc.ForceReleaseLocks
nRetVal = swDoc.ReloadOrReplace(False, UCase(swDoc.GetPathName), True)
End Select
' Message of confirmation
Dim stErr As Variant
stErr = Array("Okay", "Access error", "Version error", "Modified not reloaded error", "Invalid option", _
"File not saved error", "Invalid component error", "Unexpected error", "Component light weight error", _
"File doesn't exist error", "File invalid or same name error", "Document has no view", "Document already opened error", _
"Document event error", "Document not changed", "Reload cancel")
MsgBox CStr(stErr(nRetVal))
' ' Or we replace him
' Dim stPath As String: stPath = ...
' Dim stConfigName As String: stConfigName = ...
' Dim blRet As Boolean
' blRet = swAss.ReplaceComponents(stPath, stConfigName, True, True)
'
' If blRet Then
' MsgBox "Replacement Successful", vbInformation
' Else
' MsgBox ' Replacement failed, vbExclamation
' End If
End Sub
replace.zip