Sub CopyAModule(wkbFrom As String, wkbTo As String, strFromMod As String)
Dim wkb As Workbook
Dim strFile As String
Set wkb = Workbooks(wkbFrom)
strFile = wkb.Path & "\\vbCode.bas"
wkb.VBProject.VBComponents(strFromMod).Export strFile
On Error Resume Next
Set wkb = Workbooks(wkbTo)
If Err.Number <> 0 Then
Workbooks.Open wkbTo
Set wkb = Workbooks(wkbTo)
End If
wkb.VBProject.VBComponents.Import strFile
wkb.Save
Set wkb = Nothing
End Sub
VBA: Inject a Macro Into New Workbook From Existing Workbook
-
53
-
388
-
0
-
0
-
1
About 21 seconds
This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, so long as attribution is given to the creator. The license allows for commercial use. If you remix, adapt, or build upon the material, you must license the modified material under identical terms.