Home

Procedure Name

%3CLINGO-SUB%20id%3D%22lingo-sub-386317%22%20slang%3D%22en-US%22%3EProcedure%20Name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-386317%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20VBA%2C%20can%20you%20programmatically%20know%20the%20name%20of%20the%20procedure%20that%20is%20executing%20the%20code%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERafael%20.%3AMcPegasus.%3A%3C%2FP%3E%3CP%3EValencia%2C%20Spain%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-386317%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EVba%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-393607%22%20slang%3D%22en-US%22%3ERe%3A%20Procedure%20Name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-393607%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F73244%22%20target%3D%22_blank%22%3E%40Dan%20Moorehead%20%7C%20PowerAccess%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20You%20Dan%20for%20the%20answer.%3C%2FP%3E%3CP%3EI've%20Already%20subscribed%3B)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-390515%22%20slang%3D%22en-US%22%3ERe%3A%20Procedure%20Name%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-390515%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F306463%22%20target%3D%22_blank%22%3E%40McPegasus%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%2C%20it%20is%20not%20possible%20to%20obtain%20the%20name%20of%20the%20currently%20executing%20procedure%20or%20function%20in%20VBA.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20many%20limitations%20with%20VBA%20compared%20to%20other%20more%20modern%20languages%20like%20JavaScript%2C%20TypeScript%2C%20C%23%2C%20and%20.NET%2C%20with%20runtime%20reflection%2C%20async%20%2F%20multi-threaded%20coding%2C%20function%20pointers%2Fobjects%2Fpassing%2C%20callbacks%2C%20multiple%20classes%20per%20file%2C%20try-catch%20(vs%20On%20Error%20Go%20To)%2C%20shared%20try-catch%2Flogging%20(by%20passing%20inline%20arrow%20function%20definitions%2C%20like%20try(()%20%3D%26gt%3B%20console.log))%2C%26nbsp%3B%20easier%20debugging%2C%20more%20concise%20code%2C%20large%20class%20libraries%2C%20regex%2C%20more%20modern%20(tabbed)%20IDEs%2Feditors%2C%20and%20the%20like.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20you%20may%20find%20it%20helpful%20to%20enable%20%22Break%20in%20Class%20Module%22%20under%20VBE%20(VBA%20Editor)%20%26gt%3B%20Options%2C%20and%2For%20use%20Ctrl%2BL%20to%20show%20the%20Call%20Stack%20window%20when%20debugging%2C%20and%20add%20Watches%20there%20as%20well%20as%20use%20the%20Immediate%20Window.%20You%20can%20handle%20errors%20via%20On%20Error%20GoTo%20OnError%20statement%20for%20example%20and%20write%20error%20handling%20code%20like%20OnError%3A%20LogError(funcName)%20function%20which%20calls%20Debug.Print%2C%20but%20that%20requires%20writing%20out%20LogError(%22MyFuncName%22)%20for%20each%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20if%20you're%20scripting%20macros%20and%20events%20with%20JavaScript%20or%20C%23-like%20TypeScript%20macros%20in%26nbsp%3B%20Microsoft%20Access%20-%20as%20is%20now%20possible%20with%20the%20PowerAccess.js%20Framework%20for%20Microsoft%20Access%2C%20as%20I'd%20just%20presented%20on%20and%20demoed%20at%20Access%20Day%202019%20in%20Redmond%20last%20week%20--%20which%20makes%20it%20possible%20to%20run%20JavaScript%20without%20any%20WebBrowser%20Control%20and%20use%20any%20JavaScript%20API%20and%20library%20from%20within%20VBA%20and%20use%20the%20full%20Access%20VBA%2FAutomation%20API%20from%20JavaScript%2C%20as%20well%20as%20use%20IE11%20HTML5%20UIs%20embedded%20into%20forms%20--%20then%20you%20could%26nbsp%3B%20use%20arguments.callee%20or%20getCallerFuncName()%20(defined%20via%3A%20function%20getCallerFuncName()%20%7Breturn%20getFuncName.caller.name%3B%7D)%26nbsp%3B(when%20don't%20have%20Strict%20Mode%20enabled).%20You%20can%20also%20pass%20functions%20around%20as%20objects%2Fvariables%2C%20for%20event%20handlers%20and%20the%20like%2C%20and%20use%20var%20func%20%3D%20(arg)%20%3D%26gt%3B%20%7B%20console.log(func.name)%3B%20%7D%20for%20example.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20that%20case%2C%20you%20can%20write%20JavaScript%20macros%20(and%20C%23-like%20TypeScript%20macros%20and%20event%20handlers)%20using%20PowerAccess'%20included%20Script%20Editor%20(an%20embedded%20version%20of%20Visual%20Studio%20Code%20provided%20install-free%20with%20PowerAccess.js%20or%20with%20the%20PowerAccess%20All-in-One%20Toolset)%20or%20else%20using%20full%20Visual%20Studio%20Code%20or%20Visual%20Studio%20instead%20of%20older%20limited%20VBE.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20PowerAccess.js%2C%20you%20also%20then%20have%20access%20to%20800%2C000%20libraries%2C%20web%20APIs%20and%20NPM%20packages%20available%2C%20to%20use%20from%20VBA%20and%20JavaScript%2C%20and%20C%23-like%20TypeScript%20macros%20alike%2C%20whether%20for%20Microsoft%20Graph%2C%20Azure%20Active%20Directory%2C%20QuickBooks%2C%20FTP%2C%20web%20APIs%2C%20logging%20or%20anything%20else%20you%20could%20imagine%2C%20without%20needing%20to%20rewrite%20it%20all%20from%20scratch%20in%20VBA%2C%20and%20all%20without%20needing%20to%20compile%20and%20COM%20register%20or%20install%20(like%20an%20add-in)%20as%20needed%20with%20.NET.%26nbsp%3B%20This%20is%20why%20macro%20%26amp%3B%20Add-in%20development%20for%20Excel%20and%20the%20rest%20of%20the%20Office%20applications%20has%20moved%20to%20JavaScript%20%2F%20TypeScript%20with%20Office.js%2C%20where%20all%20the%20new%20Automation%20(Macro)%20functions%20%2F%20APIs%20are%20being%20developed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJavaScript%20%2F%20TypeScript%20is%20also%20what%20we%20had%20used%20to%20build%20PowerExcel.ai%20and%20PowerAnalytics.ai%20to%20provide%20install-free%2C%20workbook%20embedded%20Excel%20Add-ins%20for%20AI%20generated%20Power%20Query%20and%20enhanced%26nbsp%3B%20Pivot%20Tables%20and%20other%20AI%20powered%20tools%20and%20formula%20functions.%26nbsp%3B%20And%20it's%20how%20we%20brought%20rich%20Pivot%20Table%20reports%20to%20Microsoft%20Access%20(also%20provided%20as%20part%20of%20PowerAccess.js%2C%20and%20available%20for%20Excel%20as%20Power%20Reports%20for%20PowerAnalytics.ai).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOnce%20we%20began%20porting%20PowerAccess%20VBA%20Framework%20and%20PowerSQL%20Functions%20to%20TypeScript%20%2F%20JavaScript%20with%20PowerAccess.js%2C%20we've%20been%20able%20to%20simplify%20and%20speedup%20development%20greatly%2C%20and%20enable%20code%20reuse%20across%20our%20Access%20databases%2C%20Excel%2C%20SQL%20Server%2C%20mobile%2C%20Azure%20cloud%2C%20web%20and%20other%20solutions%2C%20and%20avoid%20reinventing%20the%20wheel%20through%20use%20of%20dozens%20on%20NPM%20packages%20%2F%20existing%20libraries%20and%20samples%20instead.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you're%20interested%20in%20PowerAccess.js%20for%20JavaScript%20and%20C%23-like%20TypeScript%20macros%20or%20rich%20Pivot%20Tables%20with%20end-user%20sort%2Ffilter%2Fgrouping%2C%20charts%20and%20inline%20data%20editing%2C%20then%20you%20can%20register%20as%20PowerAccess.net%20to%20get%20notified%20once%20available%20for%20early%20adopters.%26nbsp%3B%20We%20are%20planning%20to%20include%20some%20of%20our%20dozens%20of%20new%20power%20tools%20for%20MS%20Access%2C%20like%20Global%20Find%20%26amp%3B%20Replace%20and%2For%20Power%20SQL%20Editor%20(modern%20SQL%20editor%20with%20Intellisense%20code%20completion%2C%20syntax%20highlighting%2C%20Find%20%26amp%3B%20Replace%2C%20etc.)%2C%20in%20a%20free%20PowerAccess%20Express%20edition%20as%20well%2C%20in%20addition%20to%20inexpensive%20subscription%20options%20for%20all%20the%20tools%20and%20features.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAlso%2C%20if%20you're%20interested%20in%20%3CA%20href%3D%22http%3A%2F%2FPowerExcel.ai%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPowerExcel.ai%3C%2FA%3E%20AI%20power%20tools%20(like%20Power%20Query%20and%20Pivot%20Table%20auto-generation)%20and%20new%20functions%20or%20PowerAnalytics.ai%20AI%20automated%20Data%20Prep%20for%20Excel%2C%20Access%20and%20Cloud%2C%20then%20you%20can%20register%20at%20%3CA%20href%3D%22https%3A%2F%2FPowerAnalytics.ai%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPowerAnalytics.ai%3C%2FA%3E%20or%20begin%20using%20the%20cloud%20based%20version%20available%20online%20now.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20hope%20that%20helps.%3CBR%20%2F%3E%3CBR%20%2F%3EBest%20regards%2C%3C%2FP%3E%3CP%3EDan%3CBR%20%2F%3E--%3C%2FP%3E%3CP%3EDan%20Moorehead%3C%2FP%3E%3CP%3EFounder%20%26amp%3B%20CTO%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.poweraccess.net%2Fpoweraccessjs-javascript-pivottable%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPowerAccess.js%3C%2FA%3E%26nbsp%3B%20%7C%26nbsp%3B%20%3CA%20href%3D%22http%3A%2F%2FPowerExcel.ai%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPowerExcel.ai%3C%2FA%3E%26nbsp%3B%20%7C%26nbsp%3B%20%3CA%20href%3D%22https%3A%2F%2FPowerAnalytics.ai%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPowerAnalytics.ai%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
McPegasus
New Contributor

Hi,

 

In VBA, can you programmatically know the name of the procedure that is executing the code?

 

Rafael .:McPegasus.:

Valencia, Spain

2 Replies

@McPegasus 

Unfortunately, it is not possible to obtain the name of the currently executing procedure or function in VBA.

 

There are many limitations with VBA compared to other more modern languages like JavaScript, TypeScript, C#, and .NET, with runtime reflection, async / multi-threaded coding, function pointers/objects/passing, callbacks, multiple classes per file, try-catch (vs On Error Go To), shared try-catch/logging (by passing inline arrow function definitions, like try(() => console.log)),  easier debugging, more concise code, large class libraries, regex, more modern (tabbed) IDEs/editors, and the like.

 

However, you may find it helpful to enable "Break in Class Module" under VBE (VBA Editor) > Options, and/or use Ctrl+L to show the Call Stack window when debugging, and add Watches there as well as use the Immediate Window. You can handle errors via On Error GoTo OnError statement for example and write error handling code like OnError: LogError(funcName) function which calls Debug.Print, but that requires writing out LogError("MyFuncName") for each function.

 

However, if you're scripting macros and events with JavaScript or C#-like TypeScript macros in  Microsoft Access - as is now possible with the PowerAccess.js Framework for Microsoft Access, as I'd just presented on and demoed at Access Day 2019 in Redmond last week -- which makes it possible to run JavaScript without any WebBrowser Control and use any JavaScript API and library from within VBA and use the full Access VBA/Automation API from JavaScript, as well as use IE11 HTML5 UIs embedded into forms -- then you could  use arguments.callee or getCallerFuncName() (defined via: function getCallerFuncName() {return getFuncName.caller.name;}) (when don't have Strict Mode enabled). You can also pass functions around as objects/variables, for event handlers and the like, and use var func = (arg) => { console.log(func.name); } for example.

 

In that case, you can write JavaScript macros (and C#-like TypeScript macros and event handlers) using PowerAccess' included Script Editor (an embedded version of Visual Studio Code provided install-free with PowerAccess.js or with the PowerAccess All-in-One Toolset) or else using full Visual Studio Code or Visual Studio instead of older limited VBE.

 

With PowerAccess.js, you also then have access to 800,000 libraries, web APIs and NPM packages available, to use from VBA and JavaScript, and C#-like TypeScript macros alike, whether for Microsoft Graph, Azure Active Directory, QuickBooks, FTP, web APIs, logging or anything else you could imagine, without needing to rewrite it all from scratch in VBA, and all without needing to compile and COM register or install (like an add-in) as needed with .NET.  This is why macro & Add-in development for Excel and the rest of the Office applications has moved to JavaScript / TypeScript with Office.js, where all the new Automation (Macro) functions / APIs are being developed.

 

JavaScript / TypeScript is also what we had used to build PowerExcel.ai and PowerAnalytics.ai to provide install-free, workbook embedded Excel Add-ins for AI generated Power Query and enhanced  Pivot Tables and other AI powered tools and formula functions.  And it's how we brought rich Pivot Table reports to Microsoft Access (also provided as part of PowerAccess.js, and available for Excel as Power Reports for PowerAnalytics.ai).

 

Once we began porting PowerAccess VBA Framework and PowerSQL Functions to TypeScript / JavaScript with PowerAccess.js, we've been able to simplify and speedup development greatly, and enable code reuse across our Access databases, Excel, SQL Server, mobile, Azure cloud, web and other solutions, and avoid reinventing the wheel through use of dozens on NPM packages / existing libraries and samples instead.

 

If you're interested in PowerAccess.js for JavaScript and C#-like TypeScript macros or rich Pivot Tables with end-user sort/filter/grouping, charts and inline data editing, then you can register as PowerAccess.net to get notified once available for early adopters.  We are planning to include some of our dozens of new power tools for MS Access, like Global Find & Replace and/or Power SQL Editor (modern SQL editor with Intellisense code completion, syntax highlighting, Find & Replace, etc.), in a free PowerAccess Express edition as well, in addition to inexpensive subscription options for all the tools and features.


Also, if you're interested in PowerExcel.ai AI power tools (like Power Query and Pivot Table auto-generation) and new functions or PowerAnalytics.ai AI automated Data Prep for Excel, Access and Cloud, then you can register at PowerAnalytics.ai or begin using the cloud based version available online now.


I hope that helps.

Best regards,

Dan
--

Dan Moorehead

Founder & CTO, PowerAccess.js  |  PowerExcel.ai  |  PowerAnalytics.ai

@Dan Moorehead | PowerAccess 

 

Thank You Dan for the answer.

I've Already subscribed;)

 

 

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies