+ Reply to Thread
Results 1 to 10 of 10

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
    Excel 2013 Pro (work) Office 365 (home)
    Posts
    166

    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
    1,910

    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, click the 'Go Advanced' button, Then click 'Manage Attachements' and follow the menu.
    Thinking I am smart and knowing I am smart are two entirely different levels of schizophrenia.

  3. #3
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2013 Pro (work) Office 365 (home)
    Posts
    166

    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
    1,910

    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 Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,441

    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
    Excel 2013 Pro (work) Office 365 (home)
    Posts
    166

    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 Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,441

    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
    Excel 2013 Pro (work) Office 365 (home)
    Posts
    166

    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 Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,441

    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
    Excel 2013 Pro (work) Office 365 (home)
    Posts
    166

    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.

+ 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. Browse for file and set initial folder to search
    By john@fairstead.net 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