The Windows Common Dialog object used for opening/saving/colors/priniting is not licensed for use in SW VBA. You have to access it using Windows API calls (Declare...etc.).
I used to know how to do this. I forgot because now I have the full version of VB6 and everything is licensed. I have some old code that works, though.
Below is code for accessing windows common dialog thrugh Windows API. I tincludes a "Declare" statement to access the function, a "Type" statement to set up a data type needed for the API call, and a wrapper function for opening SW files. Similar contortions are required for Save dialog.
'========================================== 'begin code '========================================== ' Windows API for the Open Filebox Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _ (pOpenfilename As OPENFILENAME) As Long
' structure needed by Windows API Private Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type
Private Function FileNameToOpen() As String ' common dialog for browse for desired filename
'set variables for OPENFILENAME type Dim OFName As OPENFILENAME 'Set the filter OFName.lpstrFilter = "SW files (*.sld*)" + Chr$(0) + "*.sld*" + Chr$(0) + "SW part files (*.sldprt)" + Chr$(0) + "*.sldprt" + Chr$(0) + "SW assembly files (*.sldasm)" + Chr$(0) + "*.sldasm" + Chr$(0) + "SW drawing files (*.slddrw)" + Chr$(0) + "*.slddrw" + Chr$(0) 'default extension OFName.lpstrDefExt = "" + Chr$(0) 'Set the initial directory 'OFName.lpstrInitialDir = "" OFName.lpstrInitialDir = "C:\" 'Set the dialog title OFName.lpstrTitle = "Select SolidWorks file"
'Set the structure size OFName.lStructSize = Len(OFName) 'Create a buffer OFName.lpstrFile = Space$(254) 'Set the maximum number of chars OFName.nMaxFile = 255 'Create a buffer OFName.lpstrFileTitle = Space$(254) 'Set the maximum number of chars OFName.nMaxFileTitle = 255 'no extra flags OFName.flags = 0
'Show the 'Open File'-dialog If GetOpenFileName(OFName) Then FileNameToOpen = Trim$(OFName.lpstrFile) Else FileNameToOpen = "" End If
End Function