I've been trying the solutions I've found for similar questions, but it doesn't seem to be working to resolve my problem.
I have an Access database (Access 2016), which opens an Excel spreadsheet (Excel 2016) which does calculations. I also have an Excel Add-In file that contains a ton of UDFs. By default, I always have this Add-In installed in Excel and it's part of my profile boot script. However, when Access opens Excel through code, it doesn't recognize the Add-In (whereas opening Excel myself does work). So I've added code (per other forum suggestions) to uninstall and reinstall the Add-In after Excel opens. See code below.
Dim appExcel As Object
Dim strpath As String
strpath = "H:\Folder\Calculator.xlsm"
Set appExcel = CreateObject("Excel.Application")
appExcel.Workbooks.Open FileName:=strpath, UpdateLinks:=1, ReadOnly:=True
Set wbk = appExcel.ActiveWorkbook
appExcel.AddIns.Add FileName:="H:\Folder\AddInFile.xlam"
If appExcel.AddIns("AddInFile").Installed = False Then
appExcel.AddIns("AddInFile").Installed = True
Else
appExcel.AddIns("AddInFile").Installed = False
appExcel.AddIns("AddInFile").Installed = True
End If
Set appExcel = NothingThe only way to get my UDFs to work correctly requires me to go into every cell that contains one of these functions and manually force it to recalculate (F2-Enter). Forcing a recalculation on the entire worksheet doesn't help. It must be cell by cell. The formulas "execute" but have incorrect results until I force them to recalculate. Below is an example of one such function.
Function Nx(Age, table, Interest)
Dim l(0 To 121) As Double
Dim D1(0 To 121) As Double
Dim N1(0 To 121) As Double
Dim v As Double
Dim NAge As Double
If Age > 120 Then
NAge = 120
Else
NAge = Age
End If
l(0) = 9999.9999
v = 1 / (1 + Interest)
D1(0) = l(0)
Nn = D1(0)
x1 = Int(NAge)
x2 = Int(NAge) + 1
Fract = NAge - x1
For j = 1 To 120
l(j) = l(j - 1) * (1 - q(table, j - 1))
D1(j) = l(j) * (v ^ j)
Nn = Nn + D1(j)
Next j
N1(0) = Nn
For j = 1 To 120
N1(j) = N1(j - 1) - D1(j - 1)
Next j
Na = N1(x1) - D1(x1) * (11 / 24)
Nb = N1(x2) - D1(x2) * (11 / 24)
Nx = ((1 - Fract) * Na) + (Fract * Nb)
End Function
This function works perfectly under any other circumstance. However, when you open Excel programmatically, it stops returning correct results. If you save the file and reopen it, everything updates correctly.
I can't seem to figure out a solution. I previously asked this question, but the first response requested a sample of code and down-voted my question, and after a few weeks no one had tried answering me. I really need to figure out a solution to this, so I figured I would try again with a fresh question.
Application.Volatilein your UDF as first line.