Call them with the Application.WorksheetFunction collection. Exit Function ' Exit to calling procedure. Here. VBA: User Defined Functions (UDFs) — xlwings dev documentation Some of Excel's pre-defined functions can be used in a VBA code as well. call a SQL Server User Defined Function from Access query End Function. This eliminates the need of writing the same code over and over again. However, you can copy the code and paste it to other worksheets where you want to use them. 'it will return. End If End Function You can pass an Excel Range as a function argument, as opposed to a single cell and it will show up in Python as . MyFunction = "MyFunction: " & aa. You would use this in a cell like so: =WhereAmI () 'First declaration line shows what the function. Then you can use this VBA code: Sub Test33434 () Dim lngID As Long Dim lngReturnValue As Long lngID = 1234 With CurrentDb.QueryDefs ("qryPass") .SQL = "select dbo.testFunction (" & lngID & ")" lngReturnValue = .OpenRecordset () (0) End With End Sub So, in above we have the value we pass, and the return value. For this and more Excel tips, visit the Office Newb blog: https://www.officenewb.com/single-post/2017/10/03/Microsoft-Excel---Create-User-Defined-Functions-w. Step 3: Our end result should be either "Good" or "Bad," so the result should be in String. Gaurav Khanna. Look here: But maybe my best advice: If you are such a newbie, ask a senior colleague to help you with your first sample code. User Defined Function in VBA | How to Create UDF? (Examples) 'expects to be passed - in parens - and what. VBA - User Defined Functions - myTechMint Watch an expert doing it and listen to his explanations 2. Open the Visual Basic Editor and click Insert, Module.