StrFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT") StrFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF") StrFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _ Global Const ahtOFN_NODEREFERENCELINKS = &H100000 Global Const ahtOFN_NOLONGNAMES = &H40000 Global Const ahtOFN_NONETWORKBUTTON = &H20000 Global Const ahtOFN_NOTESTFILECREATE = &H10000 Global Const ahtOFN_NOREADONLYRETURN = &H8000 Global Const ahtOFN_CREATEPROMPT = &H2000 Global Const ahtOFN_FILEMUSTEXIST = &H1000 Global Const ahtOFN_PATHMUSTEXIST = &H800 Global Const ahtOFN_EXTENSIONDIFFERENT = &H400 Global Const ahtOFN_ALLOWMULTISELECT = &H200 'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80 'Global Const ahtOFN_ENABLETEMPLATE = &H40 Global Const ahtOFN_OVERWRITEPROMPT = &H2 ' provided the copyright notice is left unchanged.ĭeclare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _Īlias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Booleanĭeclare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _Īlias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Booleanĭeclare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long ' You are free to use it in any application, ' It is not to be altered or distributed, 'except as part of an application. ' This code was originally written by Ken Getz. StrSaveFileName = ahtCommonFileOpenSave( _įlags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY StrFilter = ahtAddFilterItem(myStrFilter, "Bitmap Files (*.bmp)", "*.bmp") StrInputFileName = ahtCommonFileOpenSave( _ĭialogTitle:="Select GPS Bitmap file to Link to Log ID.", _ StrFilter = ahtAddFilterItem(strFilter, "Bitmap Files (*.bmp)", "*.bmp") Also wondered about Vista compatibility also. I am steering towards the API because I would like to package this in a runtime and not all users may have Office installed. I would assume it is not being copied or saved because I am missing the function to store it tempory in between the open and save function. I was able to use the button to select the file and then save the file to another location, but it really isn't happening. I basically want to use a button to browse to a location and find a file and then be able to save that file to another location. I have been reading alot about this and have come to the conclusion based on some of the discussions I need to use the API method and module. Private Sub FilterTheFileDialog(dlg As Office.FileDialog, strFilter As String)Īnd you call it like this (just add a vertical bar between each standard entry).įilterTheFileDialog dlg, "Excel Files|*.xls|All Files|*.*"Īnother issue is that the SaveAs dialog doesn't accept a filter string. Net-style filter string and sets the filter index to 0
So I decided to add code that accepts a standard. Set the filter index to zero because otherwise it might not show the first filter on top - it might be second, and thus available only through the drop down menu, like thisĮxcel Files (*.XLS) <- shown only in drop down menu 'if there are multiple filters, set index to 0 Set dlg = Application.FileDialog(msoFileDialogFilePicker) Note: if the user cancels the dialog, it does not throw a runtime error.ĭim dlg As Office.FileDialog, path As String I just found out, however, that the Office.FileDialog was licensed at least to Office 2002, if not earlier, so I am licensed for it.Īnyway, here's some sample code that I recently added to my notebook. In trying to answer my own question, by the way, I'm guessing that office 2007 may have irrecoverably replaced my older version of the DLL (probably MSO.DLL). Your statement does, however, confirm my suspicion that this feature isn't well known (because most people have grown so accustomed to using the API). Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Clickĭim FolderDlgThread As = New (AddressOf getFilePathThread)įolderDlgThread.ApartmentState = ĭlgFolder.Site = Nothing ' dlgFolder is the folder browser control nameĭim stat As DialogResult = dlgFolder.Well, actually, the Office.FileDialog is a bit less code and easier to understand (and it also serves as a FolderBrowserDialog). To resolve this issue implement the code to start a new thread with ApartmentState as STA (single-threaded ) and open the folder browser dialog using the thread. If you just drag and drop a folderbrowser control and implement code to open the dialog using SHOWDIALOG method, a dialog will open up with no treeview for folder structure. Lets say you have a form designed that is being run by the installer class.In the form there is a browse button to open the FOLDER BROWSE dialog.