How to assign a value to a variable with a function that's from a COM Add-In?

KS_user

New Member
Joined
Jun 10, 2015
Messages
44
Hello everyone,

I have a COM Add-In on my Excel 2010 sheet. Does anyone have experience with such Add-Ins, and if so, have you found difficulty with using the Add-In in the same way that you would use other excel functions in VBA?

For example, I have this function "=EDS_Value" that comes from the Add-In. I used it in a macro as part of the following statement:

.Cells(i, 5).FormulaR1C1 = "=EDS_Value(MasterTagList!R" & f & "C4, RC[-1])"

and it works absolutely fine. However, when I try to assign a function output value to a variable, it flips out. The following statement:

PowerLoad = "=EDS_Value(MasterTagList!R" & f & "C5, R" & i & "C4)"

does not work. I've tried adding Application.WorksheetFunction.EDS_Value in front, but that doesn't work either. The Add-In itself has a button to make user-defined functions, so I used that to make the same function as "EDS_Value", except I called it "PointValue" (I confirmed that the PointValue and EDS_Value functions are identical by entering them into cells in a worksheet, and they generate the same value) Then, a module popped up in the VBA project window titled "EDSExcel_UserDefinedFunctions" with the following statement:

Public Function PointValue(point1, timestamp1)
PointValue = Application.COMAddIns("EDSExcel.AddinModule").Object.CallUserDefinedFunction(ThisWorkbook.Name, "PointValue", point1,timestamp1)
End Function

So I used tried to use that function syntax in a test module:

Sub Practice2()
Dim z As Double
z = Application.COMAddIns("EDSExcel.AddinModule").Object.CallUserDefinedFunction(ThisWorkbook.Name, "PointValue", Range("D9"), Range("D18"))
MsgBox z
End Sub

But 'z' is consistently zero, when the value should be around 8.9. Does anyone know why this might be? Why is it that I can use the Add-In function just fine when I enter it into a cell on the worksheet, or when I use it as part of a macro in FormulaR1C1 format, but not when I try and assign the function's output to a variable?

Last bit of information: When I started writing lines of code that use the Add-In function in ways that don't work (i.e. not R1C1 format), now, every time I save my workbook I get the message "This workbook contains features that may not be compatible with Excel Macro-Enabled workbook. Do you want to save the workbook in a new format?" I only think this might be important because the message never showed up before when I was using the Add-In functions in the R1C1 format.

Any thoughts would be appreciated, thank you!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
How about ...

Code:
PowerLoad = Evaluate("EDS_Value(MasterTagList!R" & f & "C5, R" & i & "C4)")
 
Upvote 0
Darn, it doesn't work. Thanks though! I actually didn't know about Evaluate before, it sounds like a powerful thing to have in your toolkit
 
Upvote 0
Oops. Convert the formula to A1-style references and try that.
 
Upvote 0
What did you do to get it in A1 notation?
 
Upvote 0
Here are three tries:

Sub EvalPractice1()
PowerLoad = Evaluate("EDS_Value(D18, E18)")
MsgBox PowerLoad
End Sub
(1) This one generates a "Type Mismatch" Error. When I hit 'debug' it highlights the MsgBox Powerload line. Can't figure out why....

Sub EvalPractice2()
PowerLoad = Evaluate("EDS_Value(D18, E18)")
Range("F18").Value = PowerLoad
End Sub
(2) This one does insert a value into cell F18, but it's "#NULL"

Sub EvalPractice3()
Dim point1 As String
Dim timestamp As Date
Dim PowerLoad As Double

point1 = Cells(18, 4).Value
timestamp = Cells(18, 5).Value
PowerLoad = Evaluate("EDS_Value(point1, timestamp)")
MsgBox PowerLoad
End Sub
(3) This generates the error "Type Mismatch." When I hit 'debug' the 'PowerLoad = ...' line is highlighted.
 
Upvote 0
In the last one, the code attempts to pass the literal strings "point1" and "timestamp" to the function.
 
Upvote 0
Hmm...interesting. When I run the debugger with a breakpoint at the "PowerLoad = ..." line, and hover my mouse over the 'point 1 = ..." and "timestamp = ....", the correct values appear. But when I hover my mouse over the 'point 1' and 'timestamp' within the "PowerLoad = ..." expression, no values show up. Do you know why that would be?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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