Hi,
I've found some code on a few sites that will allow the copying of a module from one workbook to another. The workbook that it is being copied to is being created in another macro so will exist for the import part. I've played with the code for some time now and cannot get it to export the module so am guessing I'm missing something very obvious in the code that I have not yet seen!!!
What I need to be able to do is copy a module (Module1 in the below) form Book1 to Book2.
For my test the above code has all files stored on the desktop, for ease.
Will then need to move over a user form as well so am hoping I can basically use the same code with reference to userforms instead of the module?
Thanks in advance for any assistance.
Steven
I've found some code on a few sites that will allow the copying of a module from one workbook to another. The workbook that it is being copied to is being created in another macro so will exist for the import part. I've played with the code for some time now and cannot get it to export the module so am guessing I'm missing something very obvious in the code that I have not yet seen!!!
What I need to be able to do is copy a module (Module1 in the below) form Book1 to Book2.
VBA Code:
Sub CopyModule()
Dim strModuleName As String
Dim strFolder As String
Dim strTempFile As String
Workbooks("Book1").Activate
strFolder = Workbooks("Book1").Path
If Len(strFolder) = 0 Then strFolder = CurDir
strFolder = strFolder & "\"
strTempFile = strFolder & "~tmpexport.bas"
On Error Resume Next
Workbooks("Book1").VBProject.VBComponents("Module1").Export strTempFile
Workbooks("Book2").VBProject.VBComponents.Import strTempFile
Kill strTempFile
On Error GoTo 0
End Sub
For my test the above code has all files stored on the desktop, for ease.
Will then need to move over a user form as well so am hoping I can basically use the same code with reference to userforms instead of the module?
Thanks in advance for any assistance.
Steven