AnsweredAssumed Answered

Macro That Changes Sheet Format (Current Sheet Only)

Question asked by James Dickson on Apr 2, 2020
Latest reply on Nov 11, 2020 by Pattabi Kakumanu

I have a macro the updates our sheet format with new formatted templates. It works great except it changes every sheet with the new format. Is there a way to only change the current sheet I'm on?


Thanks for any help you can give?  



If Update_Format.CheckBox_Change_Sheet_Format.Value = True Then

On Error Resume Next

If ComboBoxFormat.Value = "" Then

MsgBox "Select Sheet Format"


Set swApp = Application.SldWorks
Set SwModel = swApp.ActiveDoc

' Check to see if a drawing is loaded.
If SwModel Is Nothing Then
MsgBox "There is no active drawing document"
Exit Sub
End If

If SwModel.GetType <> swDocDRAWING Then
MsgBox "Open a drawing first and then TRY again!"
Exit Sub
End If

Set swDraw = SwModel

vSheetName = swDraw.GetSheetNames

' Traverse the drawing sheets and update the format

For i = 0 To UBound(vSheetName)

swDraw.ActivateSheet vSheetName(i)

Set swSheet = swDraw.GetCurrentSheet

vSheetProps = swSheet.GetProperties

'Set the sheet format to NONE
SwModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateNone, vSheetProps(2), vSheetProps(3), False, "", 0.4318, 0.2794, "Default", True

'Reload the sheet format from the speicifed location
SwModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateCustom, vSheetProps(2), vSheetProps(3), False, sTemplatepath & sTemplateName, 0.4318, 0.2794, "Default", True

Next i

swDraw.ActivateSheet vSheetName(0)
swDraw.ForceRebuild3 False
swDraw.Save3 1, nErrors, nWarnings

Set swDraw = Nothing

End If