I have a small macro on the Solidworks API to export the BOM of an open drawing to Excel in . CSV
What I would like is for this Excel file to have a fixed name and every time I run my macro, the exported BOM table from Solidworks comes to write just below the other one. I don't know enough about the code I was given, what it currently does is create a single array. I can't incorporate the instruction "write only from the moment it's empty", just to have my nomenclatures that follow one another as I execute the macro on my different planes.
If anyone has a line of code that would help me, I'm all for it!!
For example, if in a CSV file, we use the semicolon as a separator and we want to write the letters A, B and the variable C on the first line and the letters D, F and the variable F on the first line , we should write:
f = FreeFile Open "C:\TEST.csv" for append as #f Print #f, "A; B; " & C Print #f, "E; F; " & G
Close #f
With a concrete example (from the implementation of attachments in our ERP):
f = FreeFile
Open "\\dimecox3\PLANBE$\Import_plans.csv" For Append As #f opening CSV or TXT file Writing to the properties file Print #f, "ITM; 2; " & CODE & ";; 001; " & docNamePDF & "; " & "PDF" Print #f, "ITM; 2; " & CODE & ";; 002; " & docNameDWG & "; " & "DWG" Close #f
Ouch! I don't feel like it's the solution to my problem, I'm a little lost... Have you opened the code as an attachment to see the result (you need a drawing with a bill of materials for it to work).
Macro works very well! but I just want that at each RUN of the macro, the nomenclature active in solidworks starts on the same csv file, but below what may have been written appears. In this way, by going through my plans and executing the macro, I would end up with an excel that globalizes all my parts.
Clearly, I'm bad, I'm just starting out! I'm a cartoonist, and I'm discovering the power of these APIs:)
Sub ProcessBomFeature(swBomFeat As SldWorks.BomFeature)
Dim vTableArr as Variant Dim vTable as Variant Dim swTable As SldWorks.TableAnnotation Dim swAnn As SldWorks.Annotation Dim nNumCol As Long Dim nNumRow As Long Dim sRowStr As String Sun i As Long Sun j As Long
'Exit folder Dim xlsPath As String xlsPath = Mid(swModel.GetPathName, 1, InStrRev(swModel.GetPathName, "\"))
'Name of the XLS Dim xlsName As String If InStrRev(swModel.GetTitle, ".") > 0 Then xlsName = Mid(swModel.GetTitle, 1, InStrRev(swModel.GetTitle, ".") - 1) & ".csv" Else xlsName = swModel.GetTitle & ".csv" End If