Message 1 of 6
Export Parts List to Excel [VBA]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I stumbled upon a VBA code to export a parts list to excel, using the iLogic Interop.excel reference.
The code is really good, and I adjusted it to my needs, but there is one thing I can't figure out how to change.
I need to export the parts list as it is, but not including the first column.
I should include that the macro uses a company template.
My parts list in the drawing:
My parts list on the drawing.
Outcome of the macro:
Result of the current macro.
What i want from the macro:
What i want from the macro.
This is my code:
AddReference "Microsoft.Office.Interop.Excel"
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
' For debugging
'oExcel.Visible = True
'get PDF target folder path
ooFolder = ThisDoc.PathAndFileName
'get drawing name
oName = ThisDoc.FileName
'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(ooFolder) Then
System.IO.Directory.CreateDirectory(ooFolder)
End If
Dim oWB As Object
oWB = oExcel.Workbooks.Open("Z:\MecanicaDoc\MEC_PROJ\Requisição Interna XXXxx.xxxx.xlsm")
Dim oWS As Object
oWS = oWB.ActiveSheet
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
' Export the first PartsList
Dim oPL As PartsList
oPL = oSheet.PartsLists(1)
' Starting cell position on the Excel sheet
Dim iRowStart As Integer: iRowStart = 9
Dim iColStart As Integer: iColStart = 1
' Export headers
Dim iRow As Integer: iRow = iRowStart
Dim iCol As Integer: iCol = iColStart
Dim oCol As PartsListColumn
For Each oCol In oPL.PartsListColumns
oWS.Cells(iRow, iCol).Value = oCol.Title
iCol = iCol + 1
Next
iRow = iRow + 1
' Export content
Dim oRow As PartsListRow
For Each oRow In oPL.PartsListRows
iCol = iColStart
Dim oCell As PartsListCell
For Each oCell In oRow
oWS.Cells(iRow, iCol).Value = oCell.Value
iCol = iCol + 1
Next
iRow = iRow + 1
Next
'For Each oCell In oPL.PartsListColumns
' oWS.Cells(iRow, iCol).Value = ""
' iRow = iRow + 1
'Next
' Save it
' We disable the confirmation dialog
' in case the file already exists and
' needs to be overwritten
oExcel.DisplayAlerts = False
Call oWB.SaveAs(ooFolder & "\" & oName & ".xlsm")
' Close excel
Call oExcel.QuitThanks in advance!
João Silva
Mechanical Engineer

