I think the problem lies in that you need to switch the file format to .xlsm and not simply put that in the file name. In testing manually saving a macro from a macro template it defaults to .xlsx file type instead of .xlsm, user has to change the format type manually. So changing the format through code is required also. Here is a link to retrieve the integer for file format.
Change the template path in the below code
Imports System.Windows.Forms
Imports System.IO
Imports Microsoft.Office.Interop.Excel 'To use excel
Sub Main
Dim oMacroTemplate as String ="Enter fullfilename.xltm"
Dim fName As String = ThisDoc.PathAndFileName Dim xlwb As Workbook
Dim xlws As Worksheet
'Start a new instance of Excel, make visible and disable alerts
Dim excelApp As Object
excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
excelApp.DisplayAlerts = True
'Open Excel template
Try
xlwb = excelApp.Workbooks.Add(Template :=oMacroTemplate)
'xlwb = excelApp.Workbooks.Add (oMacroTemplate)'This works also
xlwb._SaveAs(FileName := fName, FileFormat := 52)'xlOpenXMLWorkbookMacroEnabled- using this text does not work in place of integer 'or
'xlwb._SaveAs(fName, 52)'This works also
'Syntax
'SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
Catch
MessageBox.Show("Cannot find XL File: Exiting", "iLogic")
Exit Sub
End Try
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan