Solved

File and Path Pickers for Visio 2013

Posted on 2013-11-29
4
1,760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 38

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

My experience with Windows 10 over a one year period and suggestions for smooth operation
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

717 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