AnsweredAssumed Answered

Change sheet format for specific sheet per file -> Help

Question asked by Tyler Banschbach on Dec 3, 2013

Hi everyone,


I'm going to attach some code that may be beneficial. What I want to do is change the format of every sheet that has the word "Packaging" in the sheet name from one sheet format to another in x amount of files per specific folder. In essence I have a folder for all of these drawings and I would like to change all of the packaging specs of each drawing in that folder from 8-1/2"x11" to 11"x17" and have everything scale appropriately. I doubt it will work that well so instead I've made a seperate sheet format that I would like to replace all of those sheets with "Packaging" in their sheet name. I know this is possible but my experience with VBA is very very limited. Heres what I have thus far:



Option Explicit


Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

Dim swFilename As String

Dim swDraw As SldWorks.DrawingDoc

Dim swSheet As SldWorks.Sheet

Dim bRet As Boolean

Dim Path As String

Dim nErrors As Long

Dim nWarnings As Long

Dim DocName As String

Dim i As Long

Dim vSheetName As Variant

Public Const sTemplatePath As String = "A:\Engineering_Files\SW Backup Files\Settings"


Sub main()



    Set swApp = Application.SldWorks


    Path = "A:\Engineering_Files\Current Product 2011\Drawings\1 Sq Picket"


    swFilename = Dir(Path & "*.SLDDRW")


    Do Until swFilename = ""

    Set swModel = swApp.OpenDoc6(Path + swFilename, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel


    vSheetName = swDraw.GetSheetNames

    For i = 0 To UBound(vSheetName)

       bRet = swDraw.ActivateSheet(vSheetName(i))



'Put the required sheet format name

       swDraw.SetupSheet4 vSheetName(i), swDwgPaperCsize, 12, 1, 1, False, sTemplatePath & "westech packaging-11x17.slddrt", 0#, 0#, "Default"



    Next i


' Switch back to first sheet and change format

    bRet = swDraw.ActivateSheet(vSheetName(0))


'Put the required sheet format name

    swDraw.SetupSheet4 vSheetName(0), swDwgPaperCsize, 12, 1, 1, False, sTemplatePath & "westech packaging-11x17.slddrt", 0#, 0#, "Default"


    swModel.ForceRebuild3 (False)




'swApp.CloseDoc swModel.GetTitle

   Set swModel = Nothing

   swFilename = Dir



MsgBox "Make sure it worked!"

End Sub