Thanks in advance.
I'm trying to call a function using a variable name. It's throwing the error
The macro 'testfunc' cannot be found. Resume without error
My Code: I tried below 3 statements but all are throwing the same error.
sFuncName = "testfunc"
ExtractData = Application.Run("Sheet.xls" & sFuncName, s1, s2)
ExtractData = Application.Run(sFuncName, s1, s2)
ExtractData = CallByName("Sheet.xls", sFuncName, VbMethod, s1, s2)
Note that the sFuncName returns a value & I have 2 Excels opened at that moment, I'm trying to copy data from one Excel to other.
Please help me in achieving this.
Private Function ABC
sFuncName = oMapWksht.Cells(sMapRowItr, 3).Value
'sFuncName = "testfunc"
ExtractData = Application.Run("Sheet.xls" & sFuncName, s1, s2)
'ExtractData = Application.Run(sFuncName, s1, s2)
'ExtractData = CallByName("Sheet.xls", sFuncName, VbMethod, s1, s2)
End Function
Public Function testfunc(ByVal s1 As String, ByVal s2 As String) As Boolean
--
---
----
End Function

testfunclocated: is it in a different workbook from the code you posted?VBAProject, make sure you put your function (such astestfunc) into a module (under the folderModulesin the Project Explorer) and not as VBA code inside a worksheet or workbook (under the folderMicrosoft Excel Objects).ExtractData = testfunc(s1,s2)?