Update 2021-03-20: I found that even if I copy the file, the one I want to reference, from my OneDrive to a local folder that's not part of OneDrive, and reference it, the same thing happens. It's only after I also rename the file that I can reference it without its path turning into a URL (assumedly pointing to my online OneDrive). This doesn't serve my needs. I'm trying to find a way to share my VBA code libraries across different apps in different locations on different devices. I may create a separate question on this if I don't figure this out.
Original Question: When I add a reference (in VBA, Tools->References) to an Excel xlsm file that is stored on my local copy of OneDrive, the path gets converted into a url and I can no longer load my VBA project without getting an error that it can't find the file. How can I make the reference ALWAYS point to my local sync'ed OneDrive path?
For example,
Open a xlsm project
Open the VBA IDE
Select Tools -> References from the VBIDE menu
Browse to add a reference to another xlsm file.
a. E.g., C:\Users\Andbio\OneDrive\Code Libraries\RYTEwayCode (XLSM).xlsmb. Make sure type xlsm is selected in the "Add Reference" File Open dialog that opens.
c. select the xlsm file you want to reference and click "Open".
d. Notice in the "Location:" field at the bottom of the "References" dialog, it shows the local path.
Click Ok to add the new reference to the project.
At this point, everything works fine and you can execute code in the file you just referenced. So, the reference works.
- Select Tools -> References, again, from the VBIDE menu
- Select the reference you just added.
- Notice, now, in the "Location:" field that the local path to your referenced file has been replace with a URL. In my case, it now says: "https://d.docs.live.net/8e13263ac9cf0594/Code Libraries/RYTEwayCode (XLSM).xlsm".
If I now save and close the XLSM file, and try to reopen it, I get an error saying it can't find the file at the URL path it showed in step 8 above. I had to reopen it in safemode (/s) to get the file opened again to remove the reference.
I know why this happens and why it was designed this way, I just need a way to get around it if there is one. Is there while still being able to store my referenced file on OneDrive and NOT storing my XLSM file on the same OneDrive?