Consulting

Results 1 to 6 of 6

Thread: Use VBA to open the dialog box to All Files instead of All Word Documents

  1. #1
    VBAX Newbie
    Joined
    May 2014
    Posts
    3
    Location

    Use VBA to open the dialog box to All Files instead of All Word Documents

    I have Word 2010 and I have code that is automatically importing a csv file into microsoft word and saving it as a pdf file. You press the button and the macro automatically opens the dialog box where the user selects the csv file to import but every time the dialog box opens the default opens with "All Word Documents" selected (only viewing word docs) but I want the default to be "All Files" so that you can actually see the CSV files and not have to manually change it every time.

    How can I change the dialog box so that it automatically opens with all "All Files" selected instead of "All Word Documents"?

    Here is the part of the code that prompts the dialog box:

    Options.DefaultFilePath(wdDocumentsPath) = "W:\Daily to Fortis\Today"
    With Dialogs(wdDialogInsertFile)
    .Name = "*.txt"
    .Show
    End With


    Thanks

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
        With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = True
            .Show
    
            For j = 1 To .SelectedItems.Count
               Documents.Add .SelectedItems(j)
            Next
        End With
    End Sub

  3. #3
    VBAX Newbie
    Joined
    May 2014
    Posts
    3
    Location
    Thanks, but when I use that different type of object it changes the file path and doesn't open up to the specified file path. In my original code (shown below) I change the default file path to "W:\Daily to Fortis\Today" but when I put your code in to replace the with part (second set of code below) it opens all file types but not to the same specified file path, even though I am still specifying the path right above that part.

    Original:
    'Get the present default filepath for documents
    defpath = Options.DefaultFilePath(wdDocumentsPath)
    'Change it to W:\
    Options.DefaultFilePath(wdDocumentsPath) = "W:\Daily to Fortis\Today"
    With Dialogs(wdDialogInsertFile)
    .Name = "*.txt"
    .Show
    End With

    With Your New Helpful Code:
    'Get the present default filepath for documents
    defpath = Options.DefaultFilePath(wdDocumentsPath)
    'Change it to W:\
    Options.DefaultFilePath(wdDocumentsPath) = "W:\Daily to Fortis\Today"
    With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = True
    .Show
    End With

    So how could I use that code you sent me to open up to the Default file path of "W:\Daily to Fortis\Today" ?

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    If you use an object, then you can use the locals window to help you see what properties and methods are associated with it:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oDl As Object
      Set oDl = Application.FileDialog(msoFileDialogFilePicker)
      With oDl
        .InitialFileName = "W:\Daily to Fortis\Today"
        .AllowMultiSelect = True
        .Show
        For j = 1 To .SelectedItems.Count
          Documents.Add .SelectedItems(j)
         Next
      End With
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted (and responded to in a different way) at: http://www.msofficeforums.com/word-v...all-files.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    VBAX Newbie
    Joined
    May 2014
    Posts
    3
    Location
    Thanks so much, thats perfect. And thanks for the link about cross-posting, i am pretty new to this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •