In another thread I mentioned that I manually renumbered my sheet names. I have the name linked to a field on the sheet. This is a good way of ordering the sheets and since I have multiple files with multiple sheets for each project. But, I have to change a lot if a sheet is inserted. Well, mentioned that I may want to create a macro. I did just that by copying a macro from the help and modifying it. I thought I'd post it in a new thread to make it easier to find... And here it is (I hope it doesn't offend anyone who knows how to properly code, but I will modify it if anyone sees anything wrong):
Edit to Add:
With guidance from I have modified the macro to first change the name of the sheets to a "dummy" name to prevent an error when renumbering the sheets if a sheet name already exists (if the above macro tries to name a sheet 2 and that name already exists, it fails). Thanks Deepak!
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim vSheetName As Variant
Dim i As Integer
Dim bRet As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
myNum = InputBox("Enter the first sheet number")
If IsNumeric(myNum) = False Then
MsgBox ("Enter a numeric value and retry")
Exit Sub
End If
' Rename the sheets to a dummy name
RenameSheets ("99999999")
RenameSheets (myNum)
End Sub
Sub RenameSheets(myName)
vSheetName = swDraw.GetSheetNames
For i = 0 To UBound(vSheetName)
mynewNum = myName + i
bRet = swDraw.ActivateSheet(vSheetName(i))
Dim swSheet As Sheet
Set swSheet = swDraw.Sheet(vSheetName(i))
If (swSheet.IsLoaded) Then
swSheet.SetName mynewNum
Else
Debug.Print (vSheetName(i) & " is not loaded.")
End If
Next i
End Sub
Edit to add2: Thanks to I copied the code written by and modified it to label past 26 views (A-Z). It should handle AA-ZZ, now (I think that works out to 702 views). A lot of workflows don't go past 26 views, but some of our drawing files do. Anyone interested can see the attached file.
Sorry Artem, my code is nowhere near as neat and tidy as yours, but what I kludged together should work.
SolidworksApi macros