Move from shared drive to Sharepoint - killed my macro

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
736
Office Version
  1. 365
Platform
  1. Windows
The IT gods moved all my files from a shared drive to sharepoint. The links within the sheets are fine but whatever magic conversion was going on didn't do anything for my macros. This leaves me stumped.

When the file was on a shared drive.....
3 cells have values that are part of a filename to open. There are several dozen links like this in the macro but they all are some version of this.
A8 = 2024
B8 = Oct
C8 = M3

The line below worked in the macro when the input file was on a shared drive to open file V:\Reports\DB\2024\UReports\M3 Oct 2024.xlsx
Workbooks.Open ("V:\Reports\DB\" & Range("A8") & "\UReports\" & Range("C8") & " " & Range("B8") & " " & Range("A8") & ".xlsx")


I need to open the file using the same 3 cells in this example. If I manually link a cell (B5) to the file, sharepoint tells me this is the link:
='https://coname-my.sharepoint.com/personal/user_coname_com/Documents/Metrics/DB/2024/UReports/[M3 Oct 2024.xlsx]10-23'!$B$5

How do I get excel to link with this http reference and use the 3 cells as input? Is it even possible to link to a sharepoint file?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
you have to go into the macros and change their file path to where the synced data is, so like %userprofile%\YourCompanyName

You could make it something like p = ThisWorkbook.path & "\Folder names\"
or just put the full paths in starting from C: drive
 
Upvote 0
Yeah - it's the syntax to do that where I'm lost.
 
Upvote 0
Open the Workbook from the SharePoint. Open the VBA Project Explorer. Double click on ThisWorkbook. Type Debug.Print ThisWorkbook.Path in the Immediate Window. That's what you will have to replace the old drive paths with.
 
Upvote 0
I have the links -see first post. The question is how do I convert the Workbooks.Open code
as in
Workbooks.Open ("V:\Reports\DB\" & Range("A8") & "\UReports\" & Range("C8") & " " & Range("B8") & " " & Range("A8") & ".xlsx")

to something that does the same thing in my macro but reference a sharepoint link instaead of a shared drive while using thos same cell references
 
Upvote 0
I have not seen done successfully yet so this is a bit of an experiment.
Run it as a stand alone sub to see if it works.

Go to an existing workbook in one of those folder and open it.
Then get the full filename & path using: File > Info > Copy Path
Does that give you a file path starting with http and containing %20 (being space characters) ?

Save that somewhere I put a copy in the same code module with it commented out (prefix of single quote)
This is just so that we can compare the result of "Debug.Print sFullName" character by character to what you saved.

Then using that build your variable sPathBase which is currently your V Drive version.
You have a folder name in that string that you replacing from cell A8. Remove that folder name between the 2 "/" characters with "@@@" as seen in the code.

Rich (BB code):
Sub SharePointWorkOpenVariables()

    Dim wsOpen As Workbook
    
    Dim sPathBase As String
    Dim sPathVariable As String
    Dim sPathFull As String
    Dim sFName As String
    Dim sFullName As String
    
    sPathBase = "V:\Reports\DB\" & "@@@" & "\UReports\"         ' Where "@@@" is a place holder - typically only one @ but want it to be obvious
    sPathVariable = Replace(Range("A8"), " ", "%20")            ' Part of folder name being swapped out
    sPathFull = Replace(sPathBase, "@@@", sPathVariable)        ' Swap out folder name
    sFName = Replace(Range("C8") & " " & Range("B8") & " " & Range("A8") & ".xlsx", " ", "%20")
    sFullName = sPathFull & sFName
    
    ' -------------------
    ' For Initial Testing
    Debug.Print sFullName
    ' -------------------
    
    Set wsOpen = Workbooks.Open(Filename:=sFullName)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,977
Messages
6,182,117
Members
453,090
Latest member
boonga

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