A simple piece of code will do it.
Sub ExportMod()
Dim ModName As String
Dim FName As Variant
ModName = "Module1"
FName = Application.GetSaveAsFilename( _
filefilter:="Module Files (*.bas),*.bas", _
Title:="Export")
If FName = False Then
' getfilename cancelled
Exit Sub
Else
On Error GoTo NoDelete:
Kill FName
End If
ThisWorkbook.VBProject.VBComponents(ModName).Export FName
Exit Sub
NoDelete:
MsgBox "The file '" & Filename & "' cannot be deleted." & vbCrLf &
_
"Error: " & CStr(Err.Number) & " " & Err.Description
End Sub
Change
ModName = "Module1"
to the name of the module you want to export. The code will prompt you
for the SaveAs file name. If you cancel this dialog, the code
terminates. If the SaveAs filename exists, the code deletes it. If
this delete operation is not successful, the module is not exported
and the code throws up a MsgBox indicating the error.
See
http://www.cpearson.com/Excel/VBE.aspx for lots more info about
working with the VBA editor via code.
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)