Results 1 to 12 of 12

Get Local Path for OneDrive synced file

Threaded View

  1. #1
    Registered User
    Join Date
    09-10-2007
    Location
    Texas, USA
    MS-Off Ver
    Office 365 (2016)
    Posts
    96

    Get Local Path for OneDrive synced file

    I am simply shocked that I have not been able to find a simple solution to this. Excel and OneDrive are both Microsoft products so you would think they would work better together.

    I am looking for a simple way to get the path of the VBA file (activeworkbook) and use it to open another file in the same folder. The problem is when the file is stored and synced in a onedrive folder.

    METHODS I HAVE TRIED:
    METHOD 1
    I tried CurDir, but this has a tendency to not be correct. I dont really understand what this is supposed to be retrieving because it is not the current directory of the active file. It seems to use the directory of the last location that was selected from within Excel. So if i open my file from within excel, then I am good to go until i open another file location from within excel, then the CurDir will be that location until the next one, and so on.

    METHOD 2
    Similar results with this most recent method i tried. i was thinking i finally found something that seemed to work, but later realized that it seemed to be behaving the same as CurDir
        Dim fso As Object
            Set fso = CreateObject("Scripting.FileSystemObject")
        Dim localPath As String
            localPath = fso.GetParentFolderName(fso.GetAbsolutePathName(Application.ActiveWorkbook.Name))
        Dim localFullFileName As String
            localFullFileName = fso.GetAbsolutePathName(Application.ActiveWorkbook.Name)
    METHOD 3
    I recently considered using the following to stop/start onedrive during the process, but not knowing the system of any given user, i thought it best to not use this method.
    Call Shell("cmd.exe /S /C" & "%LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /shutdown")
    Call Shell("cmd.exe /S /C" & "start %LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /background")
    METHOD 4
    I also looked for a way to swap the path from OneDrive sharepoint path to local synced path. so if ThisWorkbook.Path is a URL, then replace the "https://[sharepoint]/personal/[user]/Documents/" with the users local path of their onedrive, like C:\Users\[user]\[OneDrive]\ (and of course swap the remaining "/" to "\") but i have not been successful in figuring this method out.

    Does anyone here know of a way that will easily accomplish what i am trying to do?
    I have come across some posts that claim to do this for varying purposes, but they all have been very long code that I cant follow so I wouldnt know how to adapt to my needs.
    Hoping someone has a simple creative solution to this.
    Last edited by Coley356; 03-07-2022 at 05:44 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 12-21-2021, 07:25 AM
  2. Opening Excel Macro File from OneDrive not synced with Local PC - Path Issue
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-11-2021, 01:26 AM
  3. Find path to local synced sharepoint folder
    By rob vandebergh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-16-2020, 01:06 PM
  4. VBA Code to copy Files From Onedrive Folder To Local Path
    By hrayani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2020, 01:29 PM
  5. [SOLVED] Dynamic File path for OneDrive
    By Remotruker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2019, 04:54 PM
  6. Replies: 0
    Last Post: 03-24-2019, 09:18 AM
  7. [SOLVED] Get OneDrive online shared file and saved it to your local disk
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 12-10-2018, 09:14 AM

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