VB projects and XLM sheets cannot be saved in a macro-free workbook

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
3,142
Office Version
  1. 365
Platform
  1. Windows
I've had this macro running for a couple years with no issue. It basically creates a copy of a sheet in a new WB and then saves it as a .XLSX. With suppressing the alerts it has worked fine until yesterday. I did inspect my file name and is properly formed with .XLSX at the end.

This was posted with no response yet:
Redirecting

Is this a new bug in Excel?


1702075448418.png


Application.DisplayAlerts = False 'Don't display warning about changing file extension
NewWB.SaveAs Filename:=NewPathFile, FileFormat:=xlOpenXMLWorkbook 'Save to xlsx
Application.DisplayAlerts = True
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How are you copying your sheet to your workbook? Are you using the Copy method of the Worksheet object? If so, right-click the sheet tab for the sheet being copied, and select View Code. Does the code module for the worksheet containing any code/event handlers?
 
Upvote 0
Yes, this is a new bug.

Excel recently started asking absurd questions about removing the xlsm features and, by the looks of it, not allowing them to be answered/overridden in VBA

If you set DisplayAlerts to True and run the code, you'll see the prompt.

Yet another update from Microsoft which breaks things for no good reason.

I do not know of a workaround at this time.
 
Upvote 0
Sorry Jeffrey, after re-reading your post, I see that I misunderstood.

Yeah, I get the same result.

I didn't realize it until now.
 
Upvote 0
Thank you for the responses. I hope MS gets flooded with user's comments about this so they come out with a fix real fast. I have about 8 monthly reports that get saved as .XLSX on purpose to lose the VBA code. I'll allow the alerts to display for now.
 
Upvote 0
Are you on the beta channel, as I don't have any problems?
 
Upvote 0
As a workaround, maybe you could specifically delete any lines of code from the sheet's code module...

VBA Code:
    With NewWB.VBProject.VBComponents(NewWB.Sheets(1).Name).CodeModule
        .DeleteLines 1, .CountOfLines
    End With
 
    NewWB.SaveAs Filename:=NewPathFile, FileFormat:=xlOpenXMLWorkbook 'Save to xlsx

And, of course, you'll need to allow access to the VBA project object model...

VBA Code:
Developer tab >> Code group >> Macro Security >> Macro Settings >> Developer macro settings >> select/check Trust access to the VBA project object model

Hope this helps!
 
Upvote 0
@Dominic
With NewWB.VBProject.VBComponents(NewWB.Sheets(1).Name).CodeModule
.DeleteLines 1, .CountOfLines
End With

Yup, that worked. Luckily this is not used by anyone besides myself at the moment.

@Fluff
So maybe the next version coming out will fix this issue. . . and at the same time maybe they can give us the new Checkboxes they promised :biggrin:
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top