+ Reply to Thread
Results 1 to 3 of 3

VBA Code to Obtain the file path in UNC format

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    UK
    MS-Off Ver
    2013
    Posts
    4

    Talking VBA Code to Obtain the file path in UNC format

    Hi,

    I've read these forums a lot but this is my first time to register and post on here.

    I am trying to put together some VBA code for Excel to obtain UNC file paths for files on a network.

    I can get the filepath with a drive letter OK (e.g. P:\projects\drawings\plan01.dwg)
    I am having trouble converting this to a UNC type path with server name (e.g. \\servername\shareddrive\projects\drawings\plan01.dwg)

    I am passing the filepath (with drive letter) to the function 'GetUNC' below using a variable called strMappedDrive. There seems to be a problem with the function. The debugger stops at the Sharename line (starting strShare...) which is supposed to get the UNC.

    I originally found the code below on another thread and it worked OK. However I have changed it from "early binding" to "late binding" and it is not working.

    I need late binding so that different users can use the code without having to reference libraries. If I used early binding then I find the code only works if you enable Microsoft Scripting. I am using Visual Basic for Applications 6 and MS Excel 2013. I am also a beginner at VBA so go easy on me please!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA Code to Obtain the file path in UNC format

    Hi AndrewEng and welcome to ExcelForum,

    Thank you for using code tags. The following code courtesy of Microsoft may help you solve your problem. The code also uses 'Late Binding'.
    Please Login or Register  to view this content.
    I hope this helps.

    Lewis

  3. #3
    Registered User
    Join Date
    01-10-2018
    Location
    UK
    MS-Off Ver
    2013
    Posts
    4

    Re: VBA Code to Obtain the file path in UNC format

    Lewis,
    Thanks for your reply. The code works thank you.
    Andrew
    Last edited by AndrewEng; 01-11-2018 at 07:06 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. VBA Code - File Path Error
    By mebailey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2016, 10:40 PM
  2. [SOLVED] VBA code to get file path
    By Liz_Biz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-03-2014, 11:51 AM
  3. [SOLVED] VBA Code to get file names with path
    By Liz_Biz in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-23-2014, 10:38 PM
  4. Need code for hyperlink file path
    By DraftRanger in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2014, 01:07 PM
  5. Code to list the folder path and sub folder path of a specific file
    By kalai1587 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2013, 03:51 AM
  6. Browse Button Code to obtain single file name
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-29-2009, 05:34 AM
  7. code relative file path?
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2007, 03:02 AM

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