+ Reply to Thread
Results 1 to 4 of 4

Macro opens to specific folder BUT doesnt work for network drive

  1. #1
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Macro opens to specific folder BUT doesnt work for network drive

    Hello,

    The macro I use opens the search window to find a file in a specfic folder. This specific folder is located on a network drive. When first using the macro, it only opens to "My Documents" and not the specific folder. Only when I navigate to the network drive does the macro finally work from henceforth. Is there a way to correct this?
    Here is the macro I use where K is the network drive:

    Please Login or Register  to view this content.
    Thank you for any help.

    - Luke
    Last edited by Paul; 01-03-2013 at 04:12 PM. Reason: Added CODE tags. Please do so yourself in the future.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,688

    Re: Macro opens to specific folder BUT doesnt work for network drive

    ChDir changes the current directory on the specified drive but doesn't change the active drive. To change the drive too add the following line before or after your ChDir call:
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 01-03-2013 at 08:11 PM.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Macro opens to specific folder BUT doesnt work for network drive

    Thank you sir!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,688

    Re: Macro opens to specific folder BUT doesnt work for network drive

    I am going to add a little more explanation to this for those joining late. This is a carryover from DOS, and still works like this in Windows Command Line, and the file system API used by VBA. This explanation is for those who never used DOS or Windows Command Line.

    There is no one single current directory. Each drive has its own current directory. If you change which drive is active, then you get that drive's current directory. In the example above, the active drive is C. The code changes the current directory on the K drive, but C continues to be the active drive. Once you change the active drive to K you get whatever you just set the current directory to.

    This has its advantages; once you set the desired current directories it is easier to switch back and forth between drives by just giving the drive letter. But it's not completely intuitive.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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