1

I'm conducting a VBA code where I use a function defined by the company. This function is contained in a Project which is Password protected, which I will not get access to, and I'm rather sure it should not be needed.

I can call the function through the worksheet "directly", i.e. in a cell I can write =TONNES(B2,B3,B4) and the cell output is the correct value. However in VBA when I use:

Private Sub CommandButton1_Click()
   Dim param1 as String, param2 as String, param3 as String
   param1 = Cells(2,2)
   param2 = Cells(2,3)
   param3 = Cells(2,4)
   Cells(1,3) = TONNES(param1, param2, param3)
End sub

I get the error that the function TONNES is not a sub or function.

I have saved my Macro in a Module, and I don't have access to the actual code of the User defined function. Is there a way to be able to use this through VBA? As it can be used directly in the worksheet, but not through VBA, can that conclude that the function is disabled through VBA for some reason?

EDIT: The function is an add-in (more specifically I have a Company add-in which contains the data from production in a summarization page, which has created these functions in order to present these in the summarization page).

Community
  • 1
  • 1
Cenderze
  • 1,202
  • 5
  • 33
  • 56
  • If you want to put the `.Formula` in the cell it should be `Cells(1,3).Formula = "TONNES(""Parameter1"",""2"",""3"")"` – DragonSamu Sep 11 '15 at 09:37
  • @DragonSamu Thanks for your reply! What I'd like to present is a simple constant, i.e. if the formula becomes "6", then the cell should simply read 6, and not be 6, and when you examine the cell it is " `TONNES(...)` ". The same error occured when using .Formula though. – Cenderze Sep 11 '15 at 10:06
  • ya i just noticed i made an typo it should start as `= "=TONNES` – DragonSamu Sep 11 '15 at 10:09
  • Is the `Function` in an addin? – DragonSamu Sep 11 '15 at 10:12
  • @DragonSamu Yes it is an add-in. Will update my question to portray how I really use the parameters (I did not originally to reduce code). – Cenderze Sep 11 '15 at 10:19
  • The following answer might be usefull to you: [call addin function](http://stackoverflow.com/questions/375552/how-do-i-call-an-xll-addin-function-from-vba?s=1|2.1438) – DragonSamu Sep 11 '15 at 10:36

1 Answers1

1

So I've finally found a solution. Basically going into Tools -> References in the VBA Environment (Alt + F11) and adding in the specific references caused a solution to this issue. Hopefully this may be of help for someone else with this problem.

Cenderze
  • 1,202
  • 5
  • 33
  • 56