Open File Dialog Box Available in SW?

It appears SW doesn't have a File open Dialog box available in VBA. Is there a reference I need to add?

I thought I could use the Excel GetOpenFileName Dialog (code follows) This works, but obviously I'm doing something wrong here, because I get a "Server Busy - Switch Apps or Retry" Dialog right after the GetOpenFileName closes (gives me the filename, but this dialog warning is annoying) Could someone tell me what I'm doing wrong here?

Private Sub btnBrowse_Click() On Error GoTo Err_btnBrowse_Click Dim fl As File Dim eApp As New Excel.Application 'Get the path to a file with the file open dialog box Set fl = fso.GetFile(eApp.GetOpenFilename) eApp.Quit Set eApp = Nothing txtDirectory.Value = fl.ParentFolder

Err_btnBrowse_Click: 'Do Nothing End Sub

Thanks in Advance...

Reply to
What-a-Tool
Loading thread data ...

^^^^^^^^^^^^^^ < WSH reference

^^^^^^^^^^^^^^ < WSH reference

I cant tell FOR SURE, because the references are not listed in Code, but it looks as though you need to reference the Windows Scripting Host Library.

This is slow, BTW, and I have pure VB/VBA source for File open, Multiple file open, file save, browse for folder, etc, uses all API calls, and works in both VB and VBA.

I just dont feel like taking the time to add word wrap to all the lines of code so it somes thru Usenet clean. Email me and Ill send you the module....

Reply to
rocheey

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

Reply to
That70sTick

... ohhh, didnt have the str$ to set the file type list .. SNIP!!

Reply to
rocheey

Very interesting .... Thanks a bunch

Reply to
What-a-Tool

Thanks a bunch - used your code, works great - I'm opening files all over the place, now!!!

Reply to
What-a-Tool

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.