Option Compare Database
Option Explicit
Function ExportMacro(strMacro As String, Optional Destination As Variant) As String
Dim Target As String
If IsMissing(Destination) Then
Target = CurrentProject.Path & "\"
ElseIf Right(Destination, 1) = "\" Then
Target = Destination
Else
Target = Destination & "\"
End If
Application.SaveAsText acMacro, strMacro, Target & strMacro & "tmp.txt"
ExportMacro = Target & strMacro & "tmp.txt"
End Function
Function ImportMacro(strMacro As String, Source As String)
Application.LoadFromText acMacro, strMacro, Source
End Function
Function ModifyMacro(ByVal strSource As String, NewMacro As String) As String
Dim sText As String
Dim TmpFile As String
Dim ff As Long
Dim rIndex As Long
ff = FreeFile
TmpFile = Replace(strSource, "tmp", "") ' remove "tmp" from filename
Open strSource For Input As #1
Open TmpFile For Output As #2
Do Until EOF(1)
rIndex = rIndex + 1
Line Input #1, sText
If rIndex = 5 Then 'Modify the 5. line in textfile
Print #2, " Argument =""" & NewMacro & """" ' note the 4 leading spaces and the doubling up of quotes
Else
Print #2, sText
End If
Loop
Close #1
Close #2
End Function