Results 1 to 6 of 6

Thread: FileDialog

  1. #1
    Join Date
    Feb 2007
    Posts
    348

    Unanswered: FileDialog

    I have this in one VBA app. It says:

    Code:
    Public Function GetFileLocation() As String
    Dim FileLocation As Variant
    Dim ExcelFile As FileDialog
    Dim FileString As String
    
    Debug.Print "get file location'"
    Set ExcelFile = Application.FileDialog(msoFileDialogFilePicker)
    ExcelFile.Show
    For Each FileLocation In ExcelFile.SelectedItems
        Exit For
        Next
    FileString = CStr(FileLocation)
    GetFileLocation = FileString
    Debug.Print "file location: " & FileString
    End Function
    I tried putting it in a different app with:
    Code:
    Dim FilePath As String
    Dim EncryptedFile As FileDialog
    Dim FileLocations As Variant
    Debug.Print "get file location'"
    Set EncryptedFile = Application.FileDialog(msoFileDialogFilePicker)
    EncryptedFile.Show
    For Each FileLocation In EncryptedFile.SelectedItems
        Exit For
        Next
    FilePath = CStr(FileLocation)
    When I try to run it in the second app, I get an error: User-defined type not defined.

    I compared the references in both apps and don't see it.
    I did some intarwebs searching and found a suggestions that I add the windows.forms.dll to references. I did that, no change.

    Any suggestions as to why the data type FileDialog is valid in one but not the other?

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You need Microsoft Office Object Library 10.0 (or above).
    I've posted some stuff in the code bank to do with FSO - including how to add a reference programmatically.
    Might be worth a look in!
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2007
    Posts
    348
    I'm got the library referenced, version 11.0.
    I even copied the working sub from one to the other and I get the same result. I'll go check out what you have posted in the library very shortly.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Are you sure it's the office library?
    You will have the access one already but the office one is not referenced by default.
    George
    Home | Blog

  5. #5
    Join Date
    Feb 2007
    Posts
    348
    oh, sorry.
    I went back and edited that post. I must have closed the window too soon.
    Right after I typed that, I went back and looked at the refereces. I did not have the office library. I had the Access and Word libraries but not the office library.
    Thanks again for your help.

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Nay problemo!
    Feel free to nick the code to automatically add the correct reference from the code library
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •