+ Reply to Thread
Results 1 to 16 of 16

Macro to Map Drives

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Macro to Map Drives

    Hi,
    I have a issue at work where I can Map Drives but then when i reboot/log out the drives do not re-map. I have checked "Reconnect On Logon" but that does not work. I have called up IT and they just beat around the bush.

    I am wondering, if there is a way for me to create a Macro to Map drives?
    Also, for the macro to check if the drives are already mapped, if so then map it, if not then to skip mapping this drive.

    I am hoping this can be made as convenient as:

    X = C:\Documents and Settings\Pratik\Desktop\Test1

    B = C:\Documents and Settings\Pratik\Desktop\Data2

    Where the X / B specify the drive letters.

    This is not "urgent", but would be helpful.! Thank you
    Last edited by pr4t3ek; 11-08-2008 at 10:54 AM.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  2. #2
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,167
    This may be of help.
    http://groups.google.com/group/micro...f37ac8679f57e1
    Regards

    Rick
    Win10, Office 365

  3. #3
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    Infact, I have found the following:

    Please Login or Register  to view this content.
    But i just want to know what do I change the "Network" to if I want to search my Local PC, not a Network...

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    I use a WordPerfect macro at startup to do it but you could use a BAT or VBS file for bootup.

    If you want to do it with VBA:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    and how do i specify the path
    e.g C:\Documents and Settings\Pratik\Desktop

    Also, How can i create validation so that if it already exist then to not remap etc..

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    It is done by:
    Please Login or Register  to view this content.
    You can use an error routine to check if the drive exists. There are other methods of course.

    Use the /D to dismount drives.

    Here is a method to dismount the drive if it exists and sets the current user's Desktop folder to drive J:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    So if i was to map a drive which has the following path: \\USER\House
    Which is on the network, how do i go about incorporating that to the code that you have presented me?

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    Just replace my string with your string. Instead of Desktop do "\\whatever".

  9. #9
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    IF i do something like:

    Please Login or Register  to view this content.
    It does not work...

    Neither does: C:\Documents and Settings\Pratik\Desktop\Folder
    if i want to use that...

  10. #10
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Can you use the 'Specialfolders' property with any folders other than true "Special" folders such as the Desktop, Sysdir, Windir, My Documents, etc?

    I haven't used it myself, honestly, but from what I've just glanced through on various sites it doesn't appear to be used outside that realm.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello pr4t3ek,

    Here is a simple API macro to map the drive. It will also pass a password to the server if needed. This works as is with Windows 2000 and up. I used the example in your first post as the data for the macro. Change this to what you really it want it to be.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 11-08-2008 at 05:57 AM. Reason: Didn't copy the API call the first post

  12. #12
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    and what if i was to add more mappings e.g

    B: = \\user\c

    Also i know the above code only works when executed via a macro / excel.

    i was wondering if there was something more convenient like a script which i can save to my desktop or something and add it to my startup items and it will automatically execute that?

    i have the following code:

    Please Login or Register  to view this content.
    But it only works for items which are on the network, not on a local PC..

  13. #13
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    PD, your Desktop function failed because there is no SpecialFolder named as a network folder. Only certain specialfolders can be accessed that way. Some other special folders have to be accessed via API.

    For your needs, just use the method that I quoted in my last post. As I said earlier, two easy methods to make a file execute at startup are BAT files and VBS. Some administrators turn off Windows Scripting Host so it may not be available to all. Put the BAT file in your Startup folder.
    Please Login or Register  to view this content.
    It doesn't hurt to add quotes around the path as I did for drive K: which is required if the path has space characters.

    You can also map your drives via Windows Explorer, Tools, Map Network Drive.

    Pjoaquin, I used late binding but early binding makes the methods and properties available by intellisense. The properties for SpecialFolders may be found at: http://msdn.microsoft.com/en-us/libr...xe(VS.85).aspx
    Last edited by Kenneth Hobson; 11-08-2008 at 10:42 AM.

  14. #14
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    well for some reason neither of the above work except

    Please Login or Register  to view this content.
    and for me to save that as a vbs and execute that in startup.

    For some reason tools > Map Network Drive works, but it does not reconnect at login

  15. #15
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    I suppose you did check the box to Reconnect.

    When you try the BAT method, you can try it directly by clicking it in Explorer or Start > Run > filename.bat > OK.

    Sometimes, when you open a browser, the newly mapped drive will not show until you open and close the browser twice.

  16. #16
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    nah what i'll do is put the vbs file in my startup folder, so when my comp restarts etc.. it'll reconnect. I'm sure it'll work..

    i'm actually going to be going to my work in the next hour or so, so i'll test it out..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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