Solved

File Open Office.FileDialog not working

Posted on 2009-05-18
3
1,308 Views
Last Modified: 2012-05-07
The attached code was working fine until I added in some new references
They are attached
I thought I needed Office 11 Refs but as I'm using Office 2007 which is 12 I wonder what ref / change I need to make

I know I can rewrite using the more cumbersome methods but this code was very nice

Thanks in advance

Paul
Private Sub Command18_Click()

   Dim fDialog As Office.FileDialog

   

   Dim varFile As Variant
 

   ' Clear listbox contents.

   Me.TXTFileName = ""
 

   ' Set up the File Dialog.

   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
 

   With fDialog
 

      ' Allow user to make multiple selections in dialog box

      .AllowMultiSelect = False

            

      ' Set the title of the dialog box.

      .Title = "Please select the file you wish to import"
 

      ' Clear out the current filters, and add our own.

      .Filters.Clear

      .Filters.Add "Excel Files", "*.XLS"

      .Filters.Add "All Files", "*.*"
 

      ' Show the dialog box. If the .Show method returns True, the

      ' user picked at least one file. If the .Show method returns

      ' False, the user clicked Cancel.

      If .Show = True Then
 

         'Loop through each file selected and add it to our list box.

         For Each varFile In .SelectedItems

            Me.TXTFileName = varFile

         Next

      Else

         MsgBox "You clicked Cancel in the file dialog box."

      End If

   End With

End Sub

Open in new window

refs.jpg
0
Comment
Question by:Wizard_IT
3 Comments
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 250 total points
ID: 24411401
So what is the exact problem when u say it doesnt work?
that code looks fine to me

add

option explicit

on the top of your code module

then do a Debug/Compile to check of anything is wrong with that code in your environment
0
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 250 total points
ID: 24411449
I believe this has changed in Office2007.
I think you now do :
Application.FileDialog   (literally 'Application', not the name of the application)
rather than
Office.FileDialog

I don't think you need the Office12 reference (unless you need it for other things)
0
 

Accepted Solution

by:
Wizard_IT earned 0 total points
ID: 24411529
Guys
Sorry - The application wouldn't Compile

It was conincidental that I had added additional references in

used the /decompile on the command line and the application then works

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now