Forum Discussion
DavidJMorris
Nov 07, 2025Copper Contributor
Advanced Formula Editor: converting functions Names into a module
I've written a group of complicated functions using the AFE in Excel Labs. They are stored in the Name Manager. I now realize it would have been better to write these using the Modules editor. Is the...
DavidJMorris
Nov 18, 2025Copper Contributor
Hi folks, actually, this is easy to do, I wrote some VBA code that does this, since the NameManager is an object exposed in Excel VBA--not terribly elegant, little error correction, and it doesn't work with files stored on OneDrive/SharePoint because the file names are a headache. Save your file on a local drive, as an XLSM macro enabled file, copy this code into a module in VBA, then copy and paste the text file content into an Excel Lab Module:
Option Explicit
Sub ExportLambdasToTextFile()
'Code to export Excel Lab Functions written in Names editor, to text that can be copied into a module
'David Morris, 2025, free to use
Dim nm As Name
Dim fso As Object ' FileSystemObject
Dim ts As Object ' TextStream
Dim filePath As String
Const LambdaTag As String = "=LAMBDA" 'tag to filter for lambdas only
Dim LambdaLen As Integer
Dim CleanRef As String
' Define the path and filename for the output text file
filePath = ThisWorkbook.Path & "\NamedLambdas.txt" ' Saves in the same directory as the workbook; doesn't work for OneDrive files
'filePath = "D:\NamedRanges.txt"
' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the text file for writing. True creates a new file or overwrites an existing one.
Set ts = fso.CreateTextFile(filePath, True)
LambdaLen = Len(LambdaTag)
' Write a header to the text file
ts.Writeline "Excel Named Lamdas for Excel Labs Workspace"
ts.Writeline "------------------"
' Loop through each named range in the workbook
For Each nm In ThisWorkbook.Names
If Left(nm.RefersTo, LambdaLen) = LambdaTag Then
' Write the name and its reference to the text file, in tabbed format for copy and paste into Excel, to import from grid into workspace
'ts.WriteLine nm.Name & vbTab & nm.RefersTo & vbTab & "/**" & nm.Comment & "*/"
'Better solution: write text formatted to copy and paste into Module
'Output the comment formatted to be grabbed into the name space
ts.Writeline "/**" & nm.Comment & "*/"
'output the Lambda def
ts.Writeline nm.Name & " " & nm.RefersTo & ";"
'output blank line
ts.Writeline
End If
Next nm
' Close the text file
ts.Close
' Clean up objects
Set ts = Nothing
Set fso = Nothing
MsgBox "Named Lamdas exported successfully to, ready to copy and paste into Excel labs module: " & filePath, vbInformation
End Sub