Saving Worksheet via VBA

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
I have a Workbook with several Worksheets. Each worksheet has some VBA code. In one of the worksheet, I copy the worksheet to a new workbook (book2) and save, giving it a new name. The code looks something like this:

With DestWB
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
....
End With

This file extension on this is .xlsx, but there is a message that pops up to indicate it cannot save with this file extension because of macros. I can click 'Yes' to continue saving as a macro-free workbook.

Is there a way to strip the macros when the worksheet is copied? And, is there a way to by-pass prompting and automatically save as macro-free workbook?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Not sure of this but try:
Code:
With DestWB
Application.DisplayAlerts = false
    .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
    ....
  End With
Application.DisplayAlerts = True
.....
If it works to suppress the alert, Excel will strip the macros for you.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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