Option Explicit
Sub GetSwPreviewImage(strSwPreviewFilenameAndPath As String, Optional strSwConfig As String)
Dim swApp As SldWorks.SldWorks
Dim swPreview As IPictureDisp
' Dim swPreview As stdole.StdPicture 'Get Preview Bitmap Example (VB), See MSDN for details about the StdPicture object
Dim vConfName As Variant
Dim lngCount As Long
Dim boolConfigNameExists As Boolean
'Need this for SW Set swApp = Application.SldWorks
'Need this for Excel Set swApp = GetObject(, "SldWorks.Application")
vConfName = swApp.GetConfigurationNames(strSwPreviewFilenameAndPath)
If IsEmpty(vConfName) Then
vConfName = swApp.GetConfigurationNames(strSwPreviewFilenameAndPath)
End If
boolConfigNameExists = False
For lngCount = 0 To UBound(vConfName)
If vConfName(lngCount) = strSwConfig Then
boolConfigNameExists = True
End If
Next lngCount
If boolConfigNameExists Then
'nothing
Else
boolConfigNameExists = False
For lngCount = 0 To UBound(vConfName)
If vConfName(lngCount) = "Default" Then
boolConfigNameExists = True
End If
Next lngCount
If boolConfigNameExists Then
strSwConfig = "Default"
Else
strSwConfig = vConfName(1)
End If
End If
Set swPreview = swApp.GetPreviewBitmap(strSwPreviewFilenameAndPath, strSwConfig)
' Set UserForm1.Image1.Picture = swPreview
End Sub
Sub main()
Load UserForm1
Call GetSwPreviewImage("C:\Part1.SLDPRT", "Default")
UserForm1.Show
End Sub