delete buttons in new save file

amrit94

New Member
Joined
May 11, 2022
Messages
11
Office Version
  1. 2021
Platform
  1. Windows
I have the following code that works great. It copies the first sheet as an excel file (.xlsx)

The problem is that now there are Form Control buttons and Active-X buttons on the main sheet that are being copied over to the new file when saved using the code below. I don't want any buttons copied over to a new file.

I've researched for an hour on how to remove the buttons when saving the file, but can't find anything that covers this. I know I've seen this covered somewhere, but a search is not coming up with the answer I need.

Any help is greatly appreciated.
Here's the code...


Sub saveas()


Dim fn As String
Dim l As Long
Dim wb As Workbook

Set wb = ActiveWorkbook
fn = wb.FullName
l = InStrRev(fn, ".")
fn = Left(fn, l)
fn = fn & "xls"

wb.saveas Filename:=fn, FileFormat:=56




End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You are looking for this:
VBA Code:
Sheets(“SHEET NAME”).Select

ActiveSheet.Shapes.Range(Array("Button 1", "Button 2", "Button 3")).Select

Selection.Delete
 
Upvote 0
the sheets are both the same name this macro just saves it as a xls
 
Upvote 0
You'll need to work the vba I provided above in your Save As macro after wb.saveas Filename:=fn, FileFormat:=56. Then add in another ActiveWorkbook.Save after the Selection.Delete
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,230
Members
449,303
Latest member
grantrob

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