I have a simple question concerning references in excel formulas and VBA.
I am currently taking a course in asset pricing with applications in VBA. As I am very new to VBA, I have become very frustrated about a certain problem concerning solution sheets from my lecturer with reference to directories on his computer.
In the course we're gradually expanding a set pricing library called analytics.xlsm and as I understand this is a macro-enabled workbook. Within the project, there is a module containing pricing functions.
So, when I download my lecturer solution sheets all of the formulas containing pricing functions are referenced to a directory on his computer. As I understand, this is a 'link'. When I open the workbook, I have the option to change the link to my own analytics.xlsm.
I have tried this, among other things, but all I get is the #NAME? value in every cell referenced from or containing a function from analytics.xlsm.
I've tried the following in different orders and combinations:
Enabling/disabling the analytics add-in;
Updating the Reference under the Tools menu in the VBA interface to analytics.xlsm;
Updating my lecturers link with the directory on my computer containing the pricing module.
I hope that someone in here can help me understand how this works. Ideally, I would just want to download his solution workbook with formulas containing only the function written in the pricing module in which case I could just load analytics.xlsm as an add-in. This works when I solve the assignments myself.
Example:
I want
=swaprate(..,..,.....)
instead of
='machintosh......analytics.xlsm!swaprate(..,..,.....)
I'm using excel for MAC and so is my lecturer. Thank you in advance!
The reason why this happens is that the add-in file containing the function swaprate() is local. In other words:
Your lecturer opens the file analytics.xlsm with his Excel; his Excel is using an add-in, let's call it functions.xlam, and this file is stored on his local machine: for example, C:\Lectures\Financials\functions.xlam
Your lecturer inserts the external function in a cell of the analytics.xlsm, for example he writes in A1 the function =swaprate(1,2,3).
Then he uploads the file on the web to let you download it. When this happens, add-ins are lost so the file analytics.xlsm (which contains the function swaprate() referencing to his local add-in) gets the originary source path 'C:\Lectures\Financials\functions.xlam' before the name of the function.
So, technically (to test), the solution to update the link should be:
After downloading the file with the now broken links, go to "Data", then "Edit Links" and update the source of the link to where your local add-in lies;
Hence, you will now have the result as wished. Please note that if you're still seeing your local path before the function name (e.g. 'C:\Student\functions.xlam!'swaprate()) it means that this particular add-in (lying on C:\Student\) is not active. You can activate it by Options/Add-Ins menu of Excel.
Related
I'm working on a long project and there are many betas with overlapping functionality. I keep raising the number of the beta after making substantial changes.
This file imports a bunch of data from spreadsheets which are exported feeds from a SQL database. It does this with no problem and that part of it has been working for months - importing some raw data sheets and using both cell references and VB to look at it different ways, and I set up a checklist page where the end user can go through certain records one by one and classify them.
All of this works fine and I really only made a few changes today, just finishing off little bits of code that take some data from one sheet and rearrange it in another to export. It was all working with no errors and I copied the file into a new folder (which I have been doing with these templates for months), imported my data (test data in this case), and tried to run the function that copies some info from one sheet onto an another.
Then I get an error from Excel that says "we can't connect to 'https://...my.sharepoint../BETAV9_8_ItemAccountingTEMPLATEetcetc. Please make sure you're using correct web address."
After that I click OK and then I get a second message that says:
Microsoft Excel cannot access the file 'same file' There are several possible reasons:
The file name or path does not exist
The file is being used by another program
The workbook you are trying to save has the same name as a currently open workbook
This file they're telling me they can't find is like 3 betas ago and I've been using subsequent versions without getting this error. That file isn't in the current working folder, nor in the folder from which I copied it originally.
So I'm thinking I have something in my file where there's a reference to an external file, so I went through this process: https://support.microsoft.com/en-us/office/find-links-external-references-in-a-workbook-fcbf4576-3aab-4029-ba25-54313a532ff1?ui=en-us&rs=en-us&ad=us
I don't know where to begin. There is only one thing in the Name Manager (a table that I created on one of these pages with VBA so I can sort it a couple different ways) and the button that says "Delete" is grayed out. There are several references in cells to other files - but not the BETAv9_8 it's telling me it can't find. They are simply file paths/names of the files the user imported - not hidden somewhere in code, just listed on a sheet so the user can check what data she imported.
After going through all these recommended steps I still can't find anywhere in my program that mentions BETAv9_8. In the meantime I'm getting an error for a thing that worked just fine a couple hours ago.
Is this a bug? Is there something I can do to fix it?
Thanks in advance
The problem
I have eight Excel documents that are stored on a Sharepoint site. One of those documents (“receiving file”) contains formulas/cell references to the other seven documents (“source files”) on Sharepoint.
Everything works when the references are created.
Once the workbooks are saved and closed and then reopened, the receiving file no longer updates the values from the source files.
The files are synced in Windows Explorer and opened in the desktop version of Excel. Also, all eight files are opened at the same time.
The reference will first look something like this
='[Source file.xlsx]Sheet1'!$A$1
After closing and reopening, the references will look like this
='https://somecompanyname.sharepoint.com/sites/SitefortestingExcelreferences/Shared Documents/[Source file.xlsx]Sheet1'!$A$1
If I now change a value in the source value, the change will not appear in the receiving file.
What I tried so far
Setting “Calculation” to “Automatic.
Click “Calculate Now” and “Calculate Sheet”.
Double-click into the cell with the reference and hit enter.
In “Data > Queries & Connections” click “Refresh all”
In “Data > Queries & Connections > Edit Link” I clicked on update values. It did not help. However, I tried to rebuild a simple system with just two files and a single reference, and here it did work
Starting from point 5) I programmed a little macro that updates all links in all open workbooks (it did not help either):
Option Explicit
Sub UpdateAllConnections()
Dim wbWorkbook As Workbook
For Each wbWorkbook In Application.Workbooks
wbWorkbook.UpdateLink Name:=wbWorkbook.LinkSources, Type:=xlExcelLinks
Next wbWorkbook
MsgBox "Update complete.", vbInformation, "Complete"
End Sub
If I remove the path to SharePoint, so the formula looks like this
='[Source file.xlsx]Sheet1'!$A$1
It works again (until I save and reopen).
I found the following on Microsoft Answers (about OneDrive but it's probably the same issue):
https://answers.microsoft.com/en-us/msoffice/forum/all/excel-value-links-not-updating-on-onedrive/e48a7680-71e6-4a77-9eb1-e03ec7f0e3e0
I contacted the official O365 support desk and they told me this is built into the connection between Excel and OneDrive.
They have received thousands of complaints and there is no fix for it.
No option to tell Excel/Office/OneDrive to link to local copies of files on 1D by default.
No fix is planned as this is not how MS envisions how Excel/1D should be used.
My question
Any suggestions? Are there any tools in Excel that can be used to update the linked cells automatically or manually? Might SharePoint settings prevent the update?
If not, since removing the file path to SharePoint seems to work is there a way (using VBA) to remove the full file path from all cell references, so
='https://somecompanyname.sharepoint.com/sites/SitefortestingExcelreferences/Shared Documents/[Source file.xlsx]Sheet1'!$A$1
becomes
='[Source file.xlsx]Sheet1'!$A$1
I could probably loop through all cells and simply replace the path with nothing, but that would only work if I know the file path beforehand and if all the files are stored in the same SharePoint folder.
I had the same issue and here is my workaround: I can open the source file on the Sharepoint site by clicking ... and then Open in App (as opposed to Open in Browser) The referecence cell in the receiving file will become ='[Source file.xlsx]Sheet1'!$A$1 again and get automatically updated.
My workaround would be to consolidate external links onto a single sheet, and manually or use a macro to copy / hard paste to another identical page that you use for the links.
Just run the macro when you have the workbook open on your desktop to update the values.
Even simpler, you could also have a sort of database with linked values in a column and hard copies pasted into another column. This would be simpler than two identically sized sheets.
BUT, you could also go crazy and have named ranges like quarterly_total_formula and an analogue somewhere else called quarterly_total_valueonly and then write a macro to iterate over each with a for each looking for things "LIKE" *_formula and hard paste each result into the complementary *_valueonly spot... but then you'd need a macro to check that they were all paired... and by that point you might as well not waste your time in Excel and develop in Power BI, Tableau, RMarkdown, or heck learn Adobe Illustrator or work directly in HTML.
A colleague sent me a spreadsheet she uses to forecast days of coverage for a raw material. It was created by someone who is now retired, so we don't have a point of reference.
The calculation in a column of cells in the spreadsheet she sent me looks like this:
='C:\Users\username\Desktop\Forward IDS 20121114.xlam'!forwardIDS(1,F2193/0.65,E2194,E2195,E2196..)
So this function seems to read the macro at this file location, then it does a calculation with the cells in the current spreadsheet (the E# cells represent production amounts).
When I add my values to column E, it completely breaks the function, and I get a "#NAME?" error in all the cells that reference the desktop file location. I tried to save this .xlam file referenced to my desktop, then switched her username with mine, but I get the same error.
I am not really sure what the reference to this .xlam file is doing, I just need it to do the same calculations on my spreadsheet. I can find the VBA code for the Add-in via VBE, and I was even able to disable the Add-in property so I can see the underlying spreadsheet used. Maybe there is a way I can just create my own version of this with all of that information available to me?
She has created a custom function "ForwardIDS" that is stored inside that .xlam. You will have to either: A) Copy the .xlam to your computer or B) Copy the custom function into the workbook's code module.
Once you've done that you will need to update any cells that reference that function and point them to the correct location.
If you move the function to the workbook's code module you can change those formulas to just read: =forwardIDS(1,F2193/0.65,E2194,E2195,E2196..)
I wrote an Excel add-in that provides UDFs (user-defined worksheet functions).
All is well until one user sends his workbook using those functions to another user, or just tries to use the workbook on more than one computer, where the add-in has been installed to different paths.
Even if the only difference in the paths is the drive letter, when the workbook is opened on the other computer, the old full path appears on the formulas in front of all the UDFs, and the formulas return an error.
One way of dealing with that is doing a search & replace of all formulas in the workbook, replacing the path with an empty string. Then the formulas reset themselves for the add-in's path on the current computer. Sometimes I then have to go into the VBE and run a CalculateFullRebuild to get the formulas to work. Though it works, it's a lot to ask of the less technical users, and it's annoying to have to do it frequently for those users who move their workbooks around a lot.
Also -- do COM add-ins have this problem? My add-in is an xla. Though I'm curious about that, it's a moot point in this case since COM add-ins don't work on Macintosh Excel and I need this add-in to work cross-platform.
UPDATE:
As requested, here's a screenshot:
This screenshot shows what happens if Fred, who put the add-in in C:\Fred's Stuff\Fred's Excel Stuff\MyAddin.xla, sends his workbook to Martha, who put the same add-in in another path, such as C:\Martha's Files\Martha's Excel Files\MyAddin.xla, and Martha opens the file Fred sent.
If Martha deletes the path, leaving only "=MyUDF()" in the formula, Excel will find MyAddin.xla on Martha's computer in the path where Martha put it (assuming she had previously installed MyAddin.xla as an add-in in Excel), and resolve the formula correctly.
This is one of the many bugbears Excel developers need to face at one time or another, and there are a few work-arounds for it, but which one you choose will depend on your own circumstances:
http://www.jkp-ads.com/articles/FixLinks2UDF00.asp
In case the link dies, here is a summary of the three suggested methods:
Use fixed locations.
Instead of keeping your UDF code inside the addin, you create a facility that copies the UDF routine into each workbook that uses it.
Redirect the UDFs to the new location.
I'm trying to get a simple VBA function to run in an excel (.xlsm) worksheet.
I created this function:
Function abc()
abc = 2
End Function
in Module2, and it worked.
But after I copied the spreadsheet to another system, it now just shows "#name" as if it can't find it. The function shows up on the available list of functions however.
This makes me think there is some kind of setting I need to enable, but I've enabled whatever I was prompted for. Any ideas?
I should've known it was in the trust center:
http://office.microsoft.com/en-us/excel-help/change-macro-security-settings-in-excel-HP010096919.aspx
Basically, hit the ball and poke around until you find "trust" and "enable macros" and select the least secure options.
And then close and re-open the spreadsheet.
I think we may need more information. What version of Excel are you using? Is it different from the destination system version?
You'll want to make sure that Module2 was in the Workbook you copied into the other system. Excel 2007 stores macros on a personal workbook by default sometimes so you'll need to check the the code is actually inside of the .xlsm file.
If you're still stuck and need a quick fix just copy the code text into the new system's Excel workbook directly without making a .xlsm file (create new module in the other system then paste).
If you would like to learn how to put together add-ins you can get started here or here.