In order to display a table as I want on a drawing, I need to format the excel file where it is located. This goes through hiding and in some cases showing columns/rows and I would like to do it automatically so by macro but I can't do it.
I recorded a macro in excel to see the look it can have: Sub Cacher_ligne_colonne() ' 'Macro to hide the rows and columns I want Columns("B:E"). Select Selection.EntireColumn.Hidden = True Columns("I:K"). Select Selection.EntireColumn.Hidden = True Rows("35:36"). Select Range("A36"). Activate Selection.EntireRow.Hidden = True Rows("2:8"). Select Range("A8"). Activate Selection.EntireRow.Hidden = True End Sub
But I guess under SW it's not the same, maybe you just need to add xlSW somewhere? And by saving the manipulation under SW it records only the movement of the window not the "masking" action:
Dim swApp As Object
Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = _ Application.SldWorks
Set Part = swApp.ActiveDoc boolstatus = Part.Extension.SelectByID2("Parts Family", "DESIGNTABLE", 0, 0, 0, False, 0, Nothing, 0) Part.InsertFamilyTableEdit Dim myModelView As Object Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized Part.ClearSelection2 True Part.CloseFamilyTable End Sub
I think you should already open your table with this method: http://help.solidworks.com/2016/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDoc2~InsertFamilyTableEdit.html
Then you create an Excel macro and you call it from SW.
Thank you for your answer, indeed I am already opening my room family. I already have a well-developed code to choose configurations through a SW form so I already use this kind of syntax.
Being quite new to Vba programming, I didn't know that it was possible to call Excel macro* from SW. The idea would be to make a macro written in Excel but call from SW or it would run all the time? Do you have an example of code calling an Excel function from SW stp?
I'm coming back to this topic because I've done some research but I'm stuck again. I wrote a code that works in Excel in order to display all the rows and columns in a table:
Dim ShowAllLines As Integer
Dim ShowAllColumns As Integer
ShowAllLines = Columns(1).Find("", after:=[A1]).Row
Range("A1:A" & ShowAllLines).Select
Selection.EntireRow.Hidden = False
ShowAllColumns = Rows(1).Find("", after:=[A1]).Column
Range("A1:" & Chr(64 + ShowAllColumns) & "1").Select
Selection.EntireColumn.Hidden = False
This works very well from the Vba module of Excel but as soon as I switch to SW I have an error from the first line:
Dim ShowAllLines As Integer
Dim ShowAllColumns As Integer
ShowAllLines = xlWS.Columns(1).Find("", after:=[A1]).Row
xlWS.Range("A1:A" & ShowAllLines).Select
Selection.EntireRow.Hidden = False
ShowAllColumns = xlWS.Rows(1).Find("", after:=[A1]).Column
xlWS.Range("A1:" & Chr(64 + ShowAllColumns) & "1").Select
Selection.EntireColumn.Hidden = False
I guess it's in the syntax of the "Find" function that it gets stuck but I haven't found any help that already exists, that's why I'm taking the liberty of posting here.
I don't really understand what you mean because for me I already get the active sheet and workbook since I write in it. In fact, thanks to my macro, I open the 3D file, I open the associated family, I write the user's choice in a cell, I close the family, I update the family, I rebuild and there my configuration is activated.
And in this I would like to hide/show columns according to the user's choice.