+ Reply to Thread
Results 1 to 12 of 12

Need help to browse by file (msoFileDialogFilePicker) instead by folder

  1. #1
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    184

    Need help to browse by file (msoFileDialogFilePicker) instead by folder

    Hi,
    I found the following code on another site. It compares two documents and produces a new version with tracked changes. It works well, however, the code makes you browse by folder but I need to browse by file. I tried replacing msoFileDialogFolderPicker with msoFileDialogFilePicker but was getting tied up in knots with this line:

    strFileName = Dir(strFolderA & strFileSpec)

    ...it kept returning a bad result message (strFileName was null)

    Can someone with more VBA knowledge update the code so that I can pick files as opposed to folders?

    Many thanks

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    What kind of documents are you attempting to open?
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    184

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    I am trying to open Word document (.DOCX) files

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    If you arfe using FilePicker then the selected item will be the full name, i.e. the path and file name, so
    Please Login or Register  to view this content.
    would not be useable as currently defined. In fact, the Dir funtion would not really be necessary since you can use FilePicker to loop through the files you want. In the code for the FolderPicker The strFolderA variable has the separator (\) added to the path, That separator would need to be included in a version that used FilePicker if the path is broken out separately from the FullName
    Last edited by JLGWhiz; 04-30-2020 at 07:55 PM.

  5. #5
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    Try something along the lines of:
    Please Login or Register  to view this content.
    Last edited by macropod; 05-03-2020 at 06:45 PM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    184

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    Hi Paul,
    Thank you for the code - chuffed . It works almost perfect
    The code allows me to compare two documents and it generates a new document with tracked changes, e.g. Compare Result 1; however, the code prompts me to save the current MS word document while the document with tracked changes is not saved. I had a go at editing the code trying to save the ActiveDocument but I am also saving the current document. Is there any way to automatically save the newly created tracked changes document, as it needs saved anyway.

    Thanks for your help

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    You might try inserting either:
    ActiveWindow.Next.Activate
    or:
    Documents(Documents.Count).Activate
    before:
    Application.Dialogs(wdDialogFileSaveAs).Show

    It might help to move:
    Application.ScreenUpdating = True
    before:
    Application.Dialogs(wdDialogFileSaveAs).Show
    also.

  8. #8
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    184

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    Hi,
    I've tried a combination of your suggestions but the code does not save the newly created document with tracked changes.

    I use your code by opening a new blank MS Word document, inserting a new module, pasting in your code and running the macro (developer / macros). This allows me to look for Doc1 and Doc2 for comparison (thanks for that - works great!) and your code generates a new document with tracked changes. However, the code saves the blank document that I am using to run the code instead of saving the document with tracked changes (the tracked changes document always have a filename of Compare Result 1, etc.)

    Thanks for your help
    Last edited by reddwarf; 05-03-2020 at 03:25 PM.

  9. #9
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    I've revised the code in post #5. Try it now.

  10. #10
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    184

    Browse by file (msoFileDialogFilePicker) instead by folder to compare two documents

    Brilliant!! Working now.

    I see what you've done. You created a new document object (Dim DocRev As Document) and used that as the active document. Nice one. Thanks for your help
    Last edited by reddwarf; 05-04-2020 at 04:15 PM.

  11. #11
    Registered User
    Join Date
    02-12-2024
    Location
    Minneapolis, MN
    MS-Off Ver
    MS Office 265
    Posts
    1

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    This is an amazing thread and thanks so much to those who have tackled this before. Is there a way to make it such that when the dialog box that automatically comes up to save the comparison document points to the folder in which the original or revised document is in?

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Need help to browse by file (msoFileDialogFilePicker) instead by folder

    Quote Originally Posted by jk20 View Post
    This is an amazing thread and thanks so much to those who have tackled this before. Is there a way to make it such that when the dialog box that automatically comes up to save the comparison document points to the folder in which the original or revised document is in?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using FileDialog(msoFileDialogFilePicker) to choose file for Query
    By Joven76 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2019, 02:23 AM
  2. ShellApp.BrowseForFolder to give Default Folder and allow browse for any Folder
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-24-2016, 11:04 AM
  3. [SOLVED] vba get the folder of a file selected from the msofiledialogfilepicker
    By simarui in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-22-2015, 03:06 PM
  4. msoFileDialogFilePicker: How to show csv and no other file types
    By ninmjj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2013, 09:40 AM
  5. Replies: 4
    Last Post: 04-21-2013, 01:09 PM
  6. Browse for File with Suggested Folder Location?
    By Khirsah17 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2010, 09:10 AM
  7. [SOLVED] Browse for file and set initial folder to search
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2006, 04:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1