I have written this macro below. I get an error on the Workbooks(ThisWorkkBook).VBProject.VBComponents("Module1").Export strTempFile.
How do I define this?
Sub CopyModule()
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim Path As String
Dim FName As String
Dim wb2 As Workbook
Dim strModuleName As String
Dim strTempFile As String
Set wb1 = ThisWorkbook
Set ws1 = wb1.Worksheets("BackUp")
Path = ws1.Range("B14")
FName = Path & "\" & ws1.Range("B16")
strTempFile = strFolder & "~tmpexport.bas"
'On Error Resume Next '<= disabled for Debugging purpose
Workbooks(ThisWorkkBook).VBProject.VBComponents("Module1").Export strTempFile '<= changed
Workbooks(FName).VBProject.VBComponents.Import strTempFile '<= changed
Kill strTempFile
On Error GoTo 0
For Each VBComp In VBProj.VBComponents
'Check the type of the object make sure its a code module
If VBComp.Type = vbext_ct_StdModule Then
'Let the user know it's continuing
Debug.Print VBComp.Name
Debug.Print VBComp.Type
'Create the file name to export the file
Filename = "C:\Users\Alex\Desktop\Files\" + WBName + "_" + VBComp.Name + ".bas"
'Export the file.
VBComp.Export Filename:=Filename
End If
Next
'Close the active workbook
ActWrkBook.Close
'Turn off screen updates
Application.ScreenUpdating = True
End Sub
How do I define this?
Sub CopyModule()
Dim wb1 As Workbook
Dim ws1 As Worksheet
Dim Path As String
Dim FName As String
Dim wb2 As Workbook
Dim strModuleName As String
Dim strTempFile As String
Set wb1 = ThisWorkbook
Set ws1 = wb1.Worksheets("BackUp")
Path = ws1.Range("B14")
FName = Path & "\" & ws1.Range("B16")
strTempFile = strFolder & "~tmpexport.bas"
'On Error Resume Next '<= disabled for Debugging purpose
Workbooks(ThisWorkkBook).VBProject.VBComponents("Module1").Export strTempFile '<= changed
Workbooks(FName).VBProject.VBComponents.Import strTempFile '<= changed
Kill strTempFile
On Error GoTo 0
For Each VBComp In VBProj.VBComponents
'Check the type of the object make sure its a code module
If VBComp.Type = vbext_ct_StdModule Then
'Let the user know it's continuing
Debug.Print VBComp.Name
Debug.Print VBComp.Type
'Create the file name to export the file
Filename = "C:\Users\Alex\Desktop\Files\" + WBName + "_" + VBComp.Name + ".bas"
'Export the file.
VBComp.Export Filename:=Filename
End If
Next
'Close the active workbook
ActWrkBook.Close
'Turn off screen updates
Application.ScreenUpdating = True
End Sub