VBA Help

excel_learnerz

Board Regular
Joined
Dec 12, 2018
Messages
73
Hello amazing people,

I was wondering can you help me with the below

This is a current macro that I am using that copies everything (format, tab names, add data) and doesn't have formulas, removes the macros from the file also, works wonderfully, but is there a way to save the new excel into the same location automatically instead of manually saving it

Sub formula_removal()
Dim anySheet As Worksheet
ActiveWorkbook.Sheets.Copy
For Each anySheet In ActiveWorkbook.Worksheets
anySheet.UsedRange.Copy
anySheet.UsedRange.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next
Application.DisplayAlerts = False
Sheets("sheet4").Delete
Sheets("sheet5").Delete
Sheets("sheet6").Delete
Sheets("sheet7").Delete
Sheets("sheet8").Delete
Sheets("sheet9").Delete
Sheets("sheet10").Delete
Sheets("sheet11").Delete
Application.DisplayAlerts = True

End Sub


Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This is untested but might point you in the right direction:
Code:
Sub formula_removal()
Dim anySheet As Worksheet
Dim sPath As String 'path of current workbook
Dim sSaveAs As String 'file name to save as


    sPath = ThisWorkbook.Path & "\" 'path of current book
    sSaveAs = "YOURFILENAME" 'change as required
    
    ActiveWorkbook.Sheets.Copy
    ActiveWorkbook.SaveAs Filename:=sPath & sSaveAs, FileFormat:=xlOpenXMLWorkbook
    For Each anySheet In ActiveWorkbook.Worksheets
    anySheet.UsedRange.Copy
    anySheet.UsedRange.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Next
    Application.DisplayAlerts = False
    Sheets("sheet4").Delete
    Sheets("sheet5").Delete
    Sheets("sheet6").Delete
    Sheets("sheet7").Delete
    Sheets("sheet8").Delete
    Sheets("sheet9").Delete
    Sheets("sheet10").Delete
    Sheets("sheet11").Delete
    Application.DisplayAlerts = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,938
Messages
6,181,866
Members
453,068
Latest member
DCD1872

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