Why am I getting object not set error? Seems to be on this line with debug?
xlsmTarget.VBProject.VBComponents.Import "C:\New Name Test\Testv3\CreateUniqueContainers.bas"
However target seems to be set, what have I done wrong?
Sub ConvertXLSFilesToXLSM()
Dim Path As String
Dim DestPath As String
Dim xlsmTarget As Workbook
Const ModulePath As String = "C:\New Name Test\Testv3\CreateUniqueContainers.bas"
Path = "C:\New Name Test\Testv3\Files\"
DestPath = "C:\New Name Test\Testv3\Files\"
WorkFile = Dir(myPath & "*.xls")
Do While WorkFile <> ""
If Right(WorkFile, 4) <> "xlsm" Then
Workbooks.Open Filename:=Path & "\" & WorkFile
ActiveWorkbook.SaveAs Filename:= _
DestPath & WorkFile & ".xlsm",
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
xlsmTarget.VBProject.VBComponents.Import ModulePath
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
WorkFile = Dir()
Loop
End Sub