Here's my code. It's a mixture of several routines and it's still in work so don't be too critical about as it look like. It is a macro in Excel. This is what it does:
1. Asks for a path and a drawing mask.
2. Creates a list if the drawings.
3. Start loop
4. Switch to SolidWorks
5. Opens up the first drawing
6. Looks for BOM
7. If BOM not found goto #9.
8. If BOM found reads BOM into a table, opens up the associated model and reads some custom properties, closes the model
9. Close the drawing
10. Switch to Excel
11. If BOM was founs transfer data in Excel
12. Select next file name
13. Loop
And the code:
Option Explicit
Option Base 1
Dim swApp As Object
Dim swApp1 As Object
Dim swPart As Object
Dim swView As Object
Dim swBOM As Object
Const swDocDRAWING = 3
Const swOpenDocOptions_Silent = &H1
Dim sPath As String
Dim sFileSW As String
Dim iBom As Integer
Dim sMsg As String, sMask As String
Public Type BOM_Data
Item As String
Qty As String
PartNumber As String
Title As String
Matl As String
partno As String
End Type
Public LineItem() As BOM_Data
Dim nobom As Boolean, lngOha As Long
Sub ImportBOM()
'
' ImportBOM Macro
' Macro recorded 2/27/2003 by ATNAGY
'
Dim swError As Long, iPos As Long, bClose As Boolean, returnOK As Boolean
Dim nextdoc As Object, stmp As String, Model As Object
Dim sModelName As String, strConfName As String, sPartName As String
Dim strTitle As String, strPartNumber As String, strMaterial As String
Dim ret As Variant
Dim i As Integer, iItems As Integer
Dim docType As Integer, docTitle As String
'get path
sMsg = "Enter the Path to the Drawings." & vbCrLf & _
"Make sure NOT to end it with a \"
sPath = InputBox(sMsg, "Enter Drawing Path", "G:\Bra-AFAQ-All\ENG\2003\B30185 Micromatic\Mech\SW Drawings"

If sPath = "" Then
Exit Sub
Else
sPath = sPath & "\"
End If
sMsg = "Enter drawings mask (if applicable). Use '*' for all."
sMask = InputBox(sMsg, "Drawings Mask", "B30185-22*"

If sMask = "" Then sMask = "*"
'Attach to SolidWorks
On Error Resume Next
'process drawing files
sFileSW = Dir(sPath & sMask & ".slddrw"

iBom = 0
nobom = False
Set swApp = CreateObject("SldWorks.Application"

Do While sFileSW <> ""
'switch to solid works
Set swApp = GetObject(, "SldWorks.Application"

swApp.Visible = True
If Err.Number <> 0 Then
MsgBox "Can not Find SldWorks.Application" & vbCrLf & _
"ErrNo: " & Err.Number & " ErrMsg: " & Err.Description _
, vbOKOnly, "Error in ExportBOM()"
Err.Clear
GoTo CleanUp
End If
'open drawing
Set swPart = swApp.OpenDoc2(sPath & sFileSW, swDocDRAWING, False, False, True, lngOha)
If swPart Is Nothing Then
Call MsgBox("Unable to open document!", vbExclamation, "Import BOM"

' Display error message
GoTo CleanUp ' If no model currently loaded, then exit
Else
docType = swPart.GetType
docTitle = swPart.GetTitle
End If
'Get Drawing Template (first view)
Set swView = swPart.GetFirstView
'Get the BOM
Set swBOM = swView.GetBomTable
'Find the BOM - must find the view that contains the BOM
Do While swBOM Is Nothing And Not swView Is Nothing
Set swView = swView.GetNextView
Set swBOM = swView.GetBomTable
Loop
If swBOM Is Nothing Then
' Screen.MousePointer = vbDefault
' MsgBox "Can NOT find the BOM on the current drawing!"
' GoTo CleanUp
nobom = True
GoTo oha
End If
'Attach to the BOM
ret = swBOM.Attach2
If ret = False Then
MsgBox "Error Attaching to BOM"
Exit Sub
End If
'Put the BOM table in an array
iItems = swBOM.GetRowCount - 1
ReDim LineItem(iItems)
For i = 1 To iItems
LineItem(i).Item = swBOM.GetEntryText(i, 0)
LineItem(i).Qty = swBOM.GetEntryText(i, 1)
LineItem(i).PartNumber = swBOM.GetEntryText(i, 2)
LineItem(i).Title = swBOM.GetEntryText(i, 3)
LineItem(i).Matl = swBOM.GetEntryText(i, 4)
LineItem(i).partno = swBOM.GetEntryText(i, 5)
Next i
'Detach from the BOM
swBOM.Detach
'MsgBox "BOM Exported Successfully!"
'read documents data
'If doc is drawing activate model and read properties from there
'get to the referenced configuration for that
Set swView = swPart.GetFirstView 'dwg template
Set swView = swView.GetNextView 'first dwg view
'get referenced model
sModelName = swView.GetReferencedModelName()
strConfName = swView.ReferencedConfiguration
'switch to the model if it is already open
sPartName = sModelName
iPos = InStr(1, sPartName, "\"

Do While iPos > 0
sPartName = Right(sPartName, Len(sPartName) - iPos)
iPos = InStr(1, sPartName, "\"

Loop
On Error Resume Next
Set nextdoc = swApp.GetFirstDocument
stmp = nextdoc.GetTitle
bClose = True 'assume file is not open
Do While stmp <> ""
If InStr(1, stmp, sPartName) > 0 Then
If nextdoc.Visible = True Then
bClose = False 'document is already open
Else
bClose = True 'document is not open yet
End If
Exit Do
End If
Set nextdoc = nextdoc.GetNext
stmp = nextdoc.GetTitle
If Err.Number <> 0 Then Exit Do
Loop
Set Model = swApp.ActivateDoc2(sModelName, True, swError)
' get custom properties from the model
strTitle = Model.CustomInfo2(strConfName, "Title"
strPartNumber = Model.CustomInfo2(strConfName, "Drawing_No"
strMaterial = Model.CustomInfo("Material"
'reactivate drawing
'close the model
Model.Save2 True
If bClose = True Then 'only close if we had to open it
swApp.CloseDoc sModelName
End If
Set swPart = swApp.ActivateDoc2(docTitle, True, swError)
'close drawing
oha: swApp.CloseDoc docTitle
'return to Excel
Set swApp1 = GetObject(, "Excel.Application"

swApp1.Visible = True
'enter first drawing info
'if bom found
If (Not nobom) Then
'counter
iBom = iBom + 1
ActiveCell.Offset(0, 2).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = strPartNumber
ActiveCell.Offset(0, 1).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = strMaterial
ActiveCell.Offset(0, 1).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = strTitle
' ActiveCell.Offset(0, 4).Range("A1"

.Select
'enter BOM info
For i = 1 To iItems
ActiveCell.Offset(1, -4).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = LineItem(i).Item
ActiveCell.Offset(0, 1).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = LineItem(i).Qty
ActiveCell.Offset(0, 1).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = LineItem(i).PartNumber
ActiveCell.Offset(0, 1).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = LineItem(i).Matl
ActiveCell.Offset(0, 1).Range("A1"

.Select
Call SmallPause
ActiveCell.FormulaR1C1 = LineItem(i).Title
' ActiveCell.Offset(0, 1).Range("A1"

.Select
' ActiveCell.FormulaR1C1 = LineItem(i).xxx
Next i
ActiveCell.Offset(3, -4).Range("A1"

.Select
End If
' Set swApp = GetObject(, "Excel.Application"

' swApp.Visible = True
'Set swPart = swApp.ActiveDoc
'next file
sFileSW = Dir
Loop 'loop
CleanUp:
Set swApp = Nothing
Set swPart = Nothing
Set swView = Nothing
Set swBOM = Nothing
Set Model = Nothing
Set nextdoc = Nothing
End Sub
Private Sub SmallPause()
Dim PauseTime, StartTime
PauseTime = 0.25 ' Set duration.
StartTime = Timer ' Set start time.
Do While Timer < StartTime + PauseTime
' DoEvents ' Yield to other processes.
Loop
End Sub