Option Explicit
' ---------------- SolidWorks ----------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swHoleData As SldWorks.WizardHoleFeatureData2
Dim boolStatus As Boolean
' ---------------- Hole data ----------------
Dim currentStandard As Long
Dim finalStandard As Long
Dim oldType As Long
Dim newType As Long
Dim currentSSize As String
Dim currentDia As Double
Dim newSSize As String
' ---------------- Logging ----------------
Dim strSuccessLog As String
Dim strFailureLog As String
Dim intSuccessCount As Integer
Dim intFailureCount As Integer
Sub UpdateHolesWithMapping()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "Open a part document first."
Exit Sub
End If
strSuccessLog = "Updated Holes:" & vbCrLf
strFailureLog = "Failed / Skipped:" & vbCrLf
intSuccessCount = 0
intFailureCount = 0
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
If swFeat.GetTypeName = "HoleWzd" Then
Set swHoleData = swFeat.GetDefinition
' ---- Standard ----
currentStandard = swHoleData.Standard2
If currentStandard = -1 Or currentStandard = 0 Then
finalStandard = 1
Else
finalStandard = currentStandard
End If
' ---- Old type ----
oldType = swHoleData.FastenerType2
' ---- Extract size ----
currentSSize = ExtractSize(swFeat.name)
If currentSSize = "" Then
LogFail swFeat.name, "Could not extract size"
GoTo NextFeature
End If
' ---- Find current diameter FIRST ----
currentDia = ResolveCurrentDiameter(oldType, currentSSize)
If currentDia = -1 Then
LogFail swFeat.name, "Diameter not found"
GoTo NextFeature
End If
' ---- Map new type ----
newType = GetMappedType(oldType)
' ---- Resolve new ISO size ----
newSSize = ResolveNewISOSize(newType, currentDia)
If newSSize = "" Then
LogFail swFeat.name, "ISO size mapping failed"
GoTo NextFeature
End If
' ---- Apply ----
boolStatus = swHoleData.ChangeStandard(finalStandard, newType, newSSize)
If boolStatus And swFeat.ModifyDefinition(swHoleData, swModel, Nothing) Then
LogSuccess swFeat.name, oldType, newType, newSSize
Else
LogFail swFeat.name, "ChangeStandard / rebuild failed"
End If
End If
NextFeature:
Set swFeat = swFeat.GetNextFeature
Loop
swModel.ForceRebuild3 True
MsgBox BuildSummary(), vbInformation, "Hole Conversion Complete"
End Sub
Function ResolveCurrentDiameter(oldType As Long, ssize As String) As Double
Dim xl As Object, wb As Object
Dim sh1 As Object, sh2 As Object
Dim r1 As Long, r2 As Long
Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Open( _
"C:\\Harsh Tayde\\Solidworks\\SolidWorks Macro\\Working Macros\\Hole Conversion\\Hole Data\\All Counter Bore Holes.xlsx")
Set sh1 = wb.Sheets(1)
Set sh2 = wb.Sheets(2)
If LocateTypeBlock(sh1, oldType, r1, r2) Then
ResolveCurrentDiameter = FindDiaInBlock(sh1, r1, r2, ssize)
GoTo Cleanup
End If
If LocateTypeBlock(sh2, oldType, r1, r2) Then
ResolveCurrentDiameter = FindDiaInBlock(sh2, r1, r2, ssize)
GoTo Cleanup
End If
ResolveCurrentDiameter = -1
Cleanup:
wb.Close False
xl.Quit
End Function
Function ResolveNewISOSize(newType As Long, targetDia As Double) As String
Dim xl As Object, wb As Object, sh As Object
Dim r1 As Long, r2 As Long, r As Long
Dim bestDiff As Double, bestRow As Long
Set xl = CreateObject("Excel.Application")
Set wb = xl.Workbooks.Open( _
"C:\\Harsh Tayde\\Solidworks\\SolidWorks Macro\\Working Macros\\Hole Conversion\\Hole Data\\All Counter Bore Holes.xlsx")
Set sh = wb.Sheets(3)
If Not LocateTypeBlock(sh, newType, r1, r2) Then GoTo Cleanup
bestDiff = 999999
For r = r1 To r2
If Abs(sh.Cells(r, 6).Value - targetDia) < bestDiff Then
bestDiff = Abs(sh.Cells(r, 6).Value - targetDia)
bestRow = r
End If
Next
ResolveNewISOSize = sh.Cells(bestRow, 4).Value
Cleanup:
wb.Close False
xl.Quit
End Function
Function LocateTypeBlock(sh As Object, typeVal As Long, _
ByRef rStart As Long, _
ByRef rEnd As Long) As Boolean
Dim r As Long: r = 2
Do While sh.Cells(r, 3).Value <> ""
If sh.Cells(r, 3).Value = typeVal Then
rStart = r
Do While sh.Cells(r, 3).Value = typeVal
r = r + 1
Loop
rEnd = r - 1
LocateTypeBlock = True
Exit Function
End If
r = r + 1
Loop
End Function
Function FindDiaInBlock(sh As Object, rStart As Long, _
rEnd As Long, ssize As String) As Double
Dim r As Long
For r = rStart To rEnd
If UCase(Trim(sh.Cells(r, 4).Value)) = UCase(Trim(ssize)) Then
FindDiaInBlock = sh.Cells(r, 6).Value
Exit Function
End If
Next
FindDiaInBlock = -1
End Function
Function GetMappedType(oldType As Long) As Long
Select Case oldType
Case 1: GetMappedType = 28
Case 3: GetMappedType = 29
Case 6: GetMappedType = 31
Case 8: GetMappedType = 32
Case 9: GetMappedType = 33
Case 10: GetMappedType = 34
Case 13: GetMappedType = 35
Case 15: GetMappedType = 36
Case 16: GetMappedType = 37
Case 17: GetMappedType = 38
Case 18: GetMappedType = 39
Case 22: GetMappedType = 40
Case 23: GetMappedType = 41
Case 703: GetMappedType = 704
Case Else: GetMappedType = oldType
End Select
End Function
Function ExtractSize(name As String) As String
Dim p() As String
p = Split(name, "for ")
If UBound(p) < 1 Then Exit Function
ExtractSize = Split(p(1), " ")(0)
End Function
Sub LogSuccess(n As String, o As Long, nT As Long, s As String)
strSuccessLog = strSuccessLog & _
" - " & n & " | " & o & " ? " & nT & " | " & s & vbCrLf
intSuccessCount = intSuccessCount + 1
End Sub
Sub LogFail(n As String, msg As String)
strFailureLog = strFailureLog & _
" - " & n & " (" & msg & ")" & vbCrLf
intFailureCount = intFailureCount + 1
End Sub
Function BuildSummary() As String
BuildSummary = "Total Updated: " & intSuccessCount & vbCrLf & _
"Total Failed: " & intFailureCount & vbCrLf & vbCrLf & _
strSuccessLog & vbCrLf & strFailureLog
End Function[moderated]
Hello Community,
This is a macro I recently used to convert ANSI holes to ISO. It was working perfectly earlier, but today when I tried to run it again, it didn’t work.
I debugged the macro line by line, and everything seems to execute correctly. However, I noticed that ModifyDefinition is not updating the Hole Wizard feature at all, it runs without any errors but doesn’t modify the hole.
Has anyone faced a similar issue or found a solution for thisMacrohole wizard

You need to work on simplifying your macros.
I did not finish filling in all the values for the Function ChangeStandard, but I think you will get the gist of it.
This If statement may need more, but it will get you started:
If swWizardHoleFeatureData.FastenerType2 = 18 Or 19 Then
'by John R. Sitek
'02-JAN-2026
'This macro loops features to change all holes to ISO Standard
Option Explicit
Sub Main()
Dim swApplication As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swWizardHoleFeatureData As SldWorks.WizardHoleFeatureData2
Dim swWzdHoleStandardFastenerTypes As swWzdHoleStandardFastenerTypes_e
Dim vbFeatures As Variant, vbFeature As Variant
Dim vbMetricString As String
Set swApplication = Application.SldWorks
Set swModel = swApplication.ActiveDoc
vbFeatures = swModel.FeatureManager.GetFeatures(False)
'Loop features
For Each vbFeature In vbFeatures
If vbFeature.GetTypeName2 = "HoleWzd" Then
Set swWizardHoleFeatureData = vbFeature.GetDefinition
swWizardHoleFeatureData.AccessSelections swModel, Nothing
If swWizardHoleFeatureData.FastenerType2 = 18 Or 19 Then
vbMetricString = "Ø" & Round(Evaluate(swWizardHoleFeatureData.FastenerSize, True, False) * 25.4, 1)
Else
vbMetricString = swWizardHoleFeatureData.FastenerSize
End If
swWizardHoleFeatureData.ChangeStandard swStandardISO, ChangeStandard(swWizardHoleFeatureData), vbMetricString
vbFeature.ModifyDefinition swWizardHoleFeatureData, swModel, Nothing
End If
Next vbFeature
'Output to a message
MsgBox "All hole(s) set to ISO Standard where applicable.", vbOKOnly, "ISO Hole Update"
End Sub
'This function switches to ISO Fastener Type
Function ChangeStandard(swWizardHoleFeatureData As SldWorks.WizardHoleFeatureData2)
Dim vbConvertToMetric As Double
Dim vbMetricString As String
Select Case swWizardHoleFeatureData.FastenerType2
Case 62, 149, 374, 563, 661
ChangeStandard = swStandardISOCheeseHead
Case 68, 69, 116
ChangeStandard = swStandardISOCTSKFlatHead
Case 70
ChangeStandard = swStandardISOCTSKRaisedHead
Case 703, 704, 705, 706, 707, 708, 709, 711, 712
ChangeStandard = swStandardISODowelHole
Case 18, 19, 20, 24, 39, 54, 72, 92, 94, 95, 96, 117, 160, 178, 179, 182, 184, 206, 207, 210, 212, 234, 235, 238, 240, 355, 450, 550, 650
ChangeStandard = swStandardISODrillSizes
Case 3, 4, 5, 29, 45, 60, 63, 152, 664, 665, 669
ChangeStandard = swStandardISOHexBolt
' Case
' ChangeStandard = swStandardISOHexCapScrew
' Case
' ChangeStandard = swStandardISOHexMachineScrew
' Case
' ChangeStandard = swStandardISOPan
' Case
' ChangeStandard = swStandardISOScrewClearances
' Case
' ChangeStandard = swStandardISOSocketCTSKFlatHead
' Case
' ChangeStandard = swStandardISOSocketHeadCap
' Case
' ChangeStandard = swStandardISOTapDrills
' Case
' ChangeStandard = swStandardISOTaperedPipeTap
' Case
' ChangeStandard = swStandardISOTappedHole
' Case
' ChangeStandard = swStandardISOTappedHoleBottoming
End Select
End Function
Admin note: link to external drive in OP removed. Please share relevant files within the post here on 3DSwym.