Request: Macro to Export Hole Table from SolidWorks Drawing to CSV/Excel

Hello everyone,

I need help with a SolidWorks macro to export the hole table from a drawing sheet into a CSV or Excel file. The exported file name should be based on the configuration-specific property of the associated part.

Requirements:
Extract the hole table from a SolidWorks drawing sheet.
Export the hole table data (hole size, type, position, etc.) to a CSV or Excel file.
The file name should be dynamically set using a configuration-specific property from the associated part.

Environment Details:
SolidWorks Version: SolidWorks 2024/25

I’d appreciate any guidance, VBA code, or references to existing solutions.
Thanks in advance for your help!

Here is the top result of a Google search for “Macro to Export Hole Table from SolidWorks Drawing to CSV/Excel”

https://www.codestack.net/solidworks-api/document/tables/export-table-csv/

Should be a good starting point for you! If you have any specific questions we can help further.

Hello Josjh,

Thank you for your quick support.
This code is working fine, I need help regarding the exported CSV file name I want configuration properties instead of file names for the exported file name.

Something like,

Dim Length As String
Dim PartNumber As String
Dim FileName As String
PartNumber = swModel.GetCustomInfoValue(“Default”, “V_Name”)
Length= swModel.GetCustomInfoValue(“Default”, “Length”)
FileName = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "")) & PartNumber & Length


Currently, it is taking the drawing file name as a CSV file name.

Function GetExportFilePath(pathTemplate As String, model As SldWorks.ModelDoc2, tableAnn As SldWorks.TableAnnotation) As String

Const FILE_NAME_TOKEN As String = “<FileName>”
Const TABLE_NAME_TOKEN As String = “<TableName>”
Const SHEET_NAME_TOKEN As String = “<SheetName>”

Dim path As String

path = pathTemplate

If InStr(path, FILE_NAME_TOKEN) > 0 Then
path = Replace(pathTemplate, FILE_NAME_TOKEN, GetFileNameWithoutExtension(model.GetPathName()))
End If

If InStr(path, SHEET_NAME_TOKEN) > 0 Then
Dim swSheet As SldWorks.Sheet
Set swSheet = GetSheetFromTableAnnotation(model, tableAnn)
path = Replace(path, SHEET_NAME_TOKEN, swSheet.GetName())
End If

If InStr(path, TABLE_NAME_TOKEN) > 0 Then
Dim swTableFeat As SldWorks.Feature
Set swTableFeat = GetFeatureFromTableAnnotation(tableAnn)
path = Replace(path, TABLE_NAME_TOKEN, swTableFeat.Name)
End If

GetExportFilePath = GetFullPath(model, path)

End Function

Have you tried replacing the code in “GetExportFilePath” with your “something like this” code?

Yes Sir, I’m new to codding. I tried but it is not working.

Please show us what you have tried, which line gets an error, and what the error is. That way you can learn. If I just write the code for you the benefit is greatly reduced.

Thank you for not providing a direct solution, in a few days I learned so much!

I just took reference from
Export SOLIDWORKS table to CSV using VBA macro.swp (51.5 KB)
and
Export Open Drawings as PDF_DWG (SW2019) (1).zip
by Deepak Gupta. I merged both into one as per my basic understanding.

It’s now working perfectly when only a single drawing document is open. I attempted to add a second macro as a function, but I was unsuccessful. Instead, I called the second macro and used its output as the file name.

V.1 My next step is to update the code so that it runs only for the active drawing document. Alternatively, if multiple drawings are open in SolidWorks, it should export the table from all open drawings.

V.2 If I run the macro while the main assembly is open, it should open the drawing for each part, check if the table is available, and if so, export the table and close the drawing.

May I ask how you came up with your username? I wouldn’t have taken you seriously from the name to be honest.

Are you saying that because it looks like gibberish characters? You’re such a racist… ;;

Dhruv is (based on a Google search) not an uncommon Indian name. Mfg is, of course, manufacturing. BPP would by my guess for an abbreviation of a company name.

That is exactly why haha, your explanation makes total sense. I don’t often see Mfg for Manufacturing which is why it didn’t really ring as an acronym to me.

Interesting… As far as I’m aware Mfg is super common, I use it all the time. Just English I guess?

It’s probably fairly common in english and in the industrial world but being in Quebec limits my english to these forums and the internet pretty much. If I were to have to pass orders and things of that nature I’d most likely be more accustomed to it.

Anyways, sorry for the off-topicness, carry on! :laughing:

Just like a Québécois… Always causing trouble… ;;

Yes, Josh you have encoded my username correctly :smiley: