VBA File Path Issue - Sharepoint

dw1256

New Member
Joined
Jun 27, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi There,

I am using the following to assign the workbooks path to myPath:

myPath = activeworkbook.path

When I do this, it assigns the sharepoint path:

https://name.sharepoint.com/sites/sitename/Shares/Acme/Global Documents/QPCG

I want the path in this format:

C:\Users\...........\Global Documents\QPCG

Is there an easy way to do this? If not, can I somehow convert it to what I am looking for?

Thanks.
 
Sharepoint paths do not have user specific info. You really need to sync the folder first.
Also, every user could have a different path after syncing because they might have different access rights.

Using filedialog is a safe way of finding the correct path while using shared folders/files.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Returns C:\Users\myprofilename
@JEC sounds like he probably has more experience with Sharepoint than I have. I no longer have access to a sharepoint drive and have not seen anyone who has been terribly successful in accessing the path. I was just suggesting that if your full sharepoint path has 2 components a Sharepoint specific part that tends to repeat for all sharepoint folders and a 2nd folder path that is common to sharepoint and the C drive sync folder then you could do a replace of the sharepoint specific part with the Environ("UserProfile") result.

Since I can't see your full sharepoint path nor your full C drive path I can't be more specific than that.
 
Upvote 0
@JEC sounds like he probably has more experience with Sharepoint than I have. I no longer have access to a sharepoint drive and have not seen anyone who has been terribly successful in accessing the path. I was just suggesting that if your full sharepoint path has 2 components a Sharepoint specific part that tends to repeat for all sharepoint folders and a 2nd folder path that is common to sharepoint and the C drive sync folder then you could do a replace of the sharepoint specific part with the Environ("UserProfile") result.

Since I can't see your full sharepoint path nor your full C drive path I can't be more specific than that.
Here are the two paths:

https://acme.sharepoint.com/sites/Shares/Company/Global Documents/QPCG/ClientName (DW)/2022 Q2

C:\Users\ProfileName\acme.com\Shares - Company\Global Documents\QPCG\ClientName (DW)\2022 Q2

Can you offer any suggestions?
 
Upvote 0
Upvote 0
Just playing around with the combinations, this might be an option.
VBA Code:
Sub GetPath()

    Dim shareptPath As String
    Dim localPath As String
    
    ' In your case this next line would be
    ' shareptPath = ActiveWorkbook.Path
    shareptPath = "https://acme.sharepoint.com/sites/Shares/Company/Global Documents/QPCG/ClientName"
    localPath = Environ("UserProfile") & "\acme.com\Shares - Company\" _
                    & Replace(Right(shareptPath, Len(shareptPath) - InStr(shareptPath, "Company/") - Len("Company/") + 1), "/", "\") _
                    & "\"
                    
    Debug.Print localPath

End Sub
 
Upvote 0
Solution
Just playing around with the combinations, this might be an option.
VBA Code:
Sub GetPath()

    Dim shareptPath As String
    Dim localPath As String
   
    ' In your case this next line would be
    ' shareptPath = ActiveWorkbook.Path
    shareptPath = "https://acme.sharepoint.com/sites/Shares/Company/Global Documents/QPCG/ClientName"
    localPath = Environ("UserProfile") & "\acme.com\Shares - Company\" _
                    & Replace(Right(shareptPath, Len(shareptPath) - InStr(shareptPath, "Company/") - Len("Company/") + 1), "/", "\") _
                    & "\"
                   
    Debug.Print localPath

End Sub
Perfect! Thank you.
 
Upvote 0
I don't think it makes the cut for perfect ;) but if it works for you, we will take it as win :)

Thanks @JEC for pointing out that the Filedialog function returns the C drive path for the sync'd file.
 
  • Like
Reactions: JEC
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top