0 Replies Latest reply on Jan 11, 2019 8:49 AM by Rob Edwards

    Make Table From Sheet Names Macro

    Rob Edwards

       

      Option Explicit
      
      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swDrawing As SldWorks.DrawingDoc
      
      Sub main()
      
      Set swApp = Application.SldWorks
      Set swModel = swApp.ActiveDoc
      
      Select Case True
      Case swModel Is Nothing, swModel.GetType <> swDocumentTypes_e.swDocDRAWING
      Call swApp.SendMsgToUser2("Please Open a drawing and try again...", swMbInformation, swMbOk)
      Exit Sub
      End Select
      
      Set swDrawing = swModel
      
      Dim swTable As SldWorks.TableAnnotation
      Set swTable = swDrawing.InsertTableAnnotation2( _
      UseAnchorPoint:=False _
      , X:=0, Y:=0 _
      , AnchorType:=swBOMConfigurationAnchor_BottomLeft _
      , TableTemplate:="" _
      , Rows:=swDrawing.GetSheetCount _
      , Columns:=2)
      
      ' Alternate Anchor Positions
      ' swBOMConfigurationAnchor_BottomLeft
      ' swBOMConfigurationAnchor_BottomRight
      ' swBOMConfigurationAnchor_TopLeft
      ' swBOMConfigurationAnchor_TopRight
      
      swTable.Title = "Contents"
      swTable.TitleVisible = True
      
      Dim vSheetNames As Variant: vSheetNames = swDrawing.GetSheetNames
      
      Dim i As Integer
      For i = 1 To swTable.RowCount - 1
      swTable.Text(i, 0) = i
      swTable.Text(i, 1) = vSheetNames(i - 1)
      Next
      
      End Sub