Doflamingo
Board Regular
- Joined
- Apr 16, 2019
- Messages
- 238
Hi all,
I would like to transfer some moduls from a opened workbook to another one
Here is the code to create a new workbook ‘’workbook2’’ from an active worksheet of an other workbook ‘’workbook 1’’
Does someone know how to transfer the ‘’modul1’’ and the ‘’modul2’’ from the workbook1 to the workbook2
I found this on the forum
[h=2]From that thread Copy a code module from one workbook to another[/h]
but I tried to adapt it with my code and that does not work -lines of code in red-
Any idea ?
I would like to transfer some moduls from a opened workbook to another one
Here is the code to create a new workbook ‘’workbook2’’ from an active worksheet of an other workbook ‘’workbook 1’’
Does someone know how to transfer the ‘’modul1’’ and the ‘’modul2’’ from the workbook1 to the workbook2
I found this on the forum
Code:
Public Sub CopyModule() Const strModName As String = "C:\TempMod.BAS" ActiveWorkbook.VBProject.VBComponents("MyModule").Export fielname:=strModName Workbooks(2).VBProject.VBComponents.Import Filename:=strmodnamme Kill strModNameEnd Sub
but I tried to adapt it with my code and that does not work -lines of code in red-
Code:
Sub sb_Copy_Save_ActiveSheet_As_Workbook()
Dim wname As String, wfolder1 As String, wfolder2 As String
wname = ActiveSheet.Name
wfolder1 = "C:\Users\AtivBook9\Downloads\Reims\"
If Right(wfolder1, 1) <> "\" Then wfolder1 = wfolder1 & "\"
If Dir(wfolder1, vbDirectory) = "" Then
MsgBox "The folder does not exist! " & wfolder1, vbCritical
Exit Sub
End If
wfolder2 = wfolder1 & wname & "\"
If Dir(wfolder2, vbDirectory) = "" Then
MkDir wfolder2
End If
Range("E5").Value = wfolder2
ActiveSheet.Copy
ActiveWorkbook.SaveAs wfolder2 & wname & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
[COLOR=#ff0000]Const strModName As String = wfolder2 & wname & ".xlsm"
ActiveWorkbook.VBProject.VBComponents("Module3").Export fielname:=strModName
Workbooks(2).VBProject.VBComponents.Import FileName:=strmodnamme
Kill strModName[/COLOR]
End Sub
Any idea ?