+ Reply to Thread
Results 1 to 7 of 7

Open file from unspecified location using macro

  1. #1
    Forum Contributor
    Join Date
    03-13-2008
    MS-Off Ver
    Office 365
    Posts
    134

    Open file from unspecified location using macro

    Hi, i am looking for a vba that can open a file without giving location/path. I am using below code, but if i move Test.xls to any other folder it is not opening the file and giving me run-time error 1004


    Please Login or Register  to view this content.

    Any Help please
    Last edited by Fotis1991; 05-31-2017 at 04:54 AM. Reason: pls use code tags...

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Open file from unspecified location using macro

    Good morning amitmodi_mrt

    Use the standard file selection dialog so the user can choose the file and where it needs to be opened from, thus :
    Please Login or Register  to view this content.
    HTH

    DominicB

  3. #3
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Open file from unspecified location using macro

    Hi,

    First you need to be using code tags [c0de] at the start then [/c0de] at the end (replace the zeros with o's but I've done this for it to display.

    Secondly I'm sure someone can advise on this, although I can't
    Please do add reputation where you see fit, it's nice to be nice and we all enjoy a pat on the back

    Please also mark your thread as solved once it has been.

  4. #4
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,715

    Re: Open file from unspecified location using macro

    Hi
    this macro should search all subdirectories in the specified drive or root directory for a file with the name given at FindFile
    it will be rather slow if you have lots of files.
    you will need to have Microsoft Scripting Runtime checked under tools > references for it to work

    Please Login or Register  to view this content.
    Last edited by NickyC; 05-31-2017 at 04:11 AM. Reason: remove redundant code

  5. #5
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Open file from unspecified location using macro

    NickyC - I get a compile error on this line

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-13-2008
    MS-Off Ver
    Office 365
    Posts
    134

    Re: Open file from unspecified location using macro

    I m getting Run time error 70: Permission Denied on line


    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,715

    Re: Open file from unspecified location using macro

    PF Dave, do you have Microsoft Scripting Runtime checked under tools > references? If you don't please select this. If it still doesn't work, try removing scripting. from scripting.folder in the declaration.

    amitmodt_mrt The permission denied probably means you are trying to access protected or hidden folders. Try moving up the folder chain eg setting the root directory to c:\MyDocuments rather than C:\
    Last edited by NickyC; 05-31-2017 at 05:15 AM. Reason: clarification

+ 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. [SOLVED] Macro to Save Excel File to a SharePoint location and then e-mail that location in Outlook
    By NickyHavey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2016, 09:27 AM
  2. Macro: check today date with start date and open a file in stored location
    By Topa2 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-10-2016, 11:39 AM
  3. Open File Location / Select File - But don't open
    By MrGezus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2014, 09:13 AM
  4. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  5. Replies: 1
    Last Post: 10-31-2012, 11:19 AM
  6. Replies: 5
    Last Post: 09-29-2012, 12:40 PM
  7. Saving current open file to another location and format (macro)
    By flipjarg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2011, 06:26 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