Solved

File and Path Pickers for Visio 2013

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article we’ll examine containers. We’ll explore lists (http://www.experts-exchange.com/Microsoft/Applications/M…
In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

856 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