Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

File and Path Pickers for Visio 2013

Posted on 2013-11-29
4
Medium Priority
?
1,844 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 39

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 2000 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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

618 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