Solved

File and Path Pickers for Visio 2013

Posted on 2013-11-29
4
1,581 Views
Last Modified: 2013-11-30
Tried to set-up a file picker to import images

It hangs up on     Set fd = Application.FileDialog(msoFileDialogFilePicker) - error message says object not recognized?

I think the issue may be a missing reference but I'm not sure which one

Can anybody help?

Sub Main()


    'Declare a variable as a FileDialog object.

    Dim fd As FileDialog



    'Create a FileDialog object as a File Picker dialog box.

    Set fd = Application.FileDialog(msoFileDialogFilePicker)



    'Declare a variable to contain the path

    'of each selected item. Even though the path is aString,

    'the variable must be a Variant because For Each...Next

    'routines only work with Variants and Objects.

    Dim vrtSelectedItem As Variant



    'Use a With...End With block to reference the FileDialog object.

    With fd



        'Use the Show method to display the File Picker dialog box and return the user's action.

        'The user pressed the button.

    If .Show = -1 Then



            'Step through each string in the FileDialogSelectedItems collection.

            For Each vrtSelectedItem In .SelectedItems



                'vrtSelectedItem is a string that contains the path of each selected item.

                'You can use any file I/O functions that you want to work with this path.

                'This example displays the path in a message box.

                MsgBox "The path is: " & vrtSelectedItem



            Next vrtSelectedItem

        'The user pressed Cancel.

    Else

        End If

    End With



    'Set the object variable to nothing.

    Set fd = Nothing
End Sub
0
Comment
Question by:rogerdjr
  • 2
4 Comments
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
I use both the Microsoft Scripting Library and the Microsoft Office xx (your version) Library in most of my apps.  I think the Scripting library is what you need for FSO.
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
Comment Utility
Although it says that Visio has Application.FileDialog, Microsoft's on-line help is telling a small fib--Application.FileDialog will fail in Visio VBA. As a workaround, however, you can access the FileDialog object through Excel, Word or other Office applications. The code below does it using Excel.
Sub Main()
    'fd will be a FileDialog object
    Dim fd As Object
    
    'Create an Excel object. You can access the FileDialog object through it.
    Dim xl As Object
    Set xl = CreateObject("Excel.Application")
    xl.Visible = True   'This statement necessary so you can see the FileDialog.
    
    'Declare a variable to contain the path
    'of each selected item. Even though the path is aString,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant
        
    'Create a FileDialog object as a File Picker dialog box.
    Set fd = xl.FileDialog(msoFileDialogFilePicker)
    
    'Use a With...End With block to reference the FileDialog object.
    With fd
            'Use the Show method to display the File Picker dialog box and return the user's action.
            'The user pressed the button.
        If .Show = -1 Then
            xl.Visible = False  'Hide the Excel application
            
                'Step through each string in the FileDialogSelectedItems collection.
                For Each vrtSelectedItem In .SelectedItems
    
                    'vrtSelectedItem is a string that contains the path of each selected item.
                    'You can use any file I/O functions that you want to work with this path.
                    'This example displays the path in a message box.
                    MsgBox "The path is: " & vrtSelectedItem
    
                Next vrtSelectedItem
            'The user pressed Cancel.
        End If
    End With

    'Set the object variable to nothing.
    Set fd = Nothing
    Set xl = Nothing
End Sub

Open in new window

0
 

Author Closing Comment

by:rogerdjr
Comment Utility
Worked Perfect with one slight change - msoFileDialogFolderPicker picks a folder
0
 
LVL 80

Expert Comment

by:byundt
Comment Utility
rogerdjr,
Thanks for catching my mistake on msoFileDialogFilePicker vs msoFileDialogFolderPicker.

I've forwarded the issue to the responsible party at Microsoft, and hope that the on-line help gets fixed.

Brad
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

763 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

9 Experts available now in Live!

Get 1:1 Help Now