1

I have a template in which our workers can fill in the data, then the file should be saved as a new file with the Original macros from my template in it but that doesn't seem to work. The code is always removed in the new file. The template should be saved too because there's a numbering in it that has to go up with every new file created.

Does anybody know the solution?

Public Sub OpslBestand()
On Error Resume Next
Book1_BeforeSave
SavePdfEmail
Dim NieuwRet As Variant
ActiveWorkbook.Sheets.Copy  
NieuwRet = "P:\Retourformulieren\Excel\" & Range("L2").Value & "-JL-" & Format(Date, "YYYYMMDD") & "-" & Range("Klant").Value
ActiveWorkbook.SaveAs NieuwRet, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close
VolgRet
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
3
  • Guys i found the problem... It's this line ActiveWorkbook.Sheets.Copy this should be Workbook.Sheets.copy and then the macro is in the new file Commented Sep 8, 2017 at 9:45
  • When you do a Sheets.Copy it copies the sheets (and any macros in those sheets) to a new workbook, but won't copy any non-worksheet macros. Commented Sep 8, 2017 at 9:48
  • Yes that's the one thanks for your answer too, it was a luck for me that i tried this Commented Sep 8, 2017 at 9:48

1 Answer 1

2

If you save the file as .xlsx, the macro will be deleted. You need to save the file as .xlsm (macro-enabled).

Sign up to request clarification or add additional context in comments.

1 Comment

ActiveWorkbook.SaveAs NieuwRet, FileFormat:=xlOpenXMLWorkbookMacroEnabled will save as a macro-enabled file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.