Results 1 to 2 of 2
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Late binding for MSO file dialog

    Hello everyone!



    I am trying to wrap my head around late binding, so as not to have to set references. I got it figured out for Outlook, but cannot for the life of me get it to work for the file dialog function. Currently I'm getting an error on the 5th line - User defined type not defined. I got lines 2,3 and 4 from another site. Well, I got the whole thing from somewhere else and added 2-4. Thoughts and guidance as always will be greatly appreciated!

    Code:
    Public Function FSBrowse()
     Dim oFS  As Object
    Set oFS = CreateObject("Scripting.FileSystemObject")
    Dim varEntry As Variant
        Dim fdf As FileDialogFilter
        FSBrowse = ""
        With Application.FileDialog(dialogType:=lngType)
            'Set the title to match the type used from the list
            .Title = "Browse for "
            Select Case lngType
            Case msoFileDialogOpen
                .Title = .Title & "File to open"
            Case msoFileDialogSaveAs
                .Title = .Title & "File to SaveAs"
            Case msoFileDialogFilePicker
                .Title = .Title & "File"
            Case msoFileDialogFolderPicker
                .Title = .Title & "Folder"
            End Select
            'Reset then add filter patterns separated by tildes (~) where multiple
            '  extensions are separated by semi-colons (;) and the description is
            '  separated from them by a comma (,).
            '  Example strPattern "MS Access,*.MDB; *.ACCDB~MS Excel,*.XLS; *.XLSX"
            Call .Filters.Clear
            For Each varEntry In Split(strPattern, "~")
    '            Call .Filters.Add(Description:=Split(varEntry, ",")(0), _
    '                              Extensions:=Split(varEntry, ",")(1))
            Next varEntry
            'Set some default settings
            .InitialFileName = strStart
            .AllowMultiSelect = False
            .InitialView = msoFileDialogViewDetails
            'Only return a value from the FileDialog if not cancelled.
            If .Show Then FSBrowse = .SelectedItems(1)
        End With
    End Function

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    by line 5 I presume you mean

    Dim fdf As FileDialogFilter

    FileDialogFilter is specific to the reference module and (without checking) will likely be a number or an object

    you are likely to have the same issue with msoFileDialogOpen etc

    Temporarily add back the MSO reference library then hit F2 to open the ObjectBrowser. Search for FileDialogFilter and you will see the type/value at the bottom.

    Alternatively if the code is running (with library installed), you can hover of the variables to see the values or use the immediate window

    so it may be you will then need to redeclare as

    Dim fdf As Object

    or if numbers

    Const fdf =1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Outlook late binding to create a new contact
    By sdel_nevo in forum Programming
    Replies: 1
    Last Post: 11-09-2016, 10:15 AM
  2. Using Late Binding in creating custom ribbons
    By Demerit in forum Programming
    Replies: 2
    Last Post: 08-25-2015, 04:17 PM
  3. Late Binding Outlook Tasks and Appointments
    By sstiebinger in forum Programming
    Replies: 2
    Last Post: 08-21-2015, 02:20 PM
  4. send outlook email with late binding
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 01-24-2014, 09:39 AM
  5. How do I achieve late binding on a Chart?
    By RocketMonkey in forum Forms
    Replies: 1
    Last Post: 02-12-2013, 02:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums