I want to add a new sheet in a Macro Enabled Excel File using VBA.
It doesn\'t matter the method that I use:
Try this code in your xlsm file:
Dim ws As Worksheet
Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
And let me know if this doesn't work.
I was experiencing the same issue, on a Windows 7 computer with Excel version 16.0.10730.20264 32-bit, the code ran fine without issue. However, on a Windows 10 computer with the same Excel install version, the macro would immediately stop execution following the Sheets.Add or Worksheets.Add line. I found that this was only happening where I was attempting to add a sheet to a workbook that contained VBA code. The issue is caused by the macro security settings on the computer. If you set Automation Security to Low before opening the workbook, you should no longer get the error: Application.AutomationSecurity = msoAutomationSecurityLow