Solved

File and Path Pickers for Visio 2013

Posted on 2013-11-29
4
1,642 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 35

Expert Comment

by:PatHartman
ID: 39686453
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 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39686486
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
ID: 39687408
Worked Perfect with one slight change - msoFileDialogFolderPicker picks a folder
0
 
LVL 81

Expert Comment

by:byundt
ID: 39687504
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically someone asks me whether there’s a way to automatically convert all of the pages in a Visio drawing to PowerPoint slides. There have even been a few times when I’ve wanted to do that myself but I never really had enough incentive to figu…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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