Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use the File Dialog box in Micosoft Office VBA instead of VS .NET FileDialog clumsy one

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I did like the one VS offers, it is not the one that OFFICE USES.
I use this VBA code to open a File Dialog box in Excel many times. I create forms and have a button to open it. I like it sicne it is the exact one that Windows uses. It requires this reference. Microsoft Office xx Object Library. xx being the version of Office you have installed. I do not like the File Ddialofg in Visual studio. It is very clumsy when you drill down to many directlries to find a file. It shows the folder picked at the very bottom of its window each time.
I added the only Imports it showed Imports Microsoft.Office.Core but it does not work.
How can I use the Office one in VS? what referene do I need to add? I treid the only one
I added the Microsoft Office xx Object Library but the lines in yellow are not accepted
Code to run the Office Dialog box
Code:
Dim fDialog As [highlight #FCE94F]Office.FileDialog[/highlight]
        Dim varFile As Object
        ' Set up the File Dialog.
        fDialog = [highlight #FCE94F]Application.FileDialog(msoFileDialogFilePicker)[/highlight]
        With fDialog
            ' Allow user to make multiple selections in dialog box
            .AllowMultiSelect = True
            ' Set the title of the dialog box.
            .Title = "Please select Resource SOW Workers Excel sheet"
            ' Clear out the current filters, and add our own.
            .Filters.Clear()
            .Filters.Add("Access Databases", "*.XLS")
            .Filters.Add("All Files", "*.*")
            If .Show = True Then

                'Loop through each file selected and add it to our list box.
                For Each varFile In .SelectedItems
                    ExcelFileName = varFile
                Next
                'import excel file
                ' DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel9, "tmp-SOWResourceList", ExcelFileName, False)
            Else
                'MsgBox "You clicked Cancel in the file dialog box."
            End If
        End With
    End Sub

DougP
 
have a look here...
You need to access it via Microsoft.Office.Core

But I have seen a lot of post about a potential bug plus it is not being recommended as you are tying your application to an office environment.


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top