VBA Save as new workbook Use MACRO ON NEW workbook?

Melimob

Active Member
Joined
Oct 16, 2011
Messages
396
Office Version
  1. 365
Hi All

Not sure if this can be done?

Ultimately I want to create a new workbook without formulas with a part dynamic file name but the user selects the folder.

I was thinking I could:

a) SaveAs 'File name would read a cell +todays date'.
b) user chooses path
c) saves
d) in newly saved wkbook? copy and pastes over itself to remove formulas
e) deletes unwanted sheets
f) saves again

The code I have for this is below but I didn't know how to do a) from above?
also, it's not saving as a new file it just writes over this one?

I guess I should also add a box in case the file already exists it asks if they want to overwrite?

Code:
Sub SaveAsNewWkbook_New()
    
    RemoveFilters1a
        
    Application.GetSaveAsFilename ActiveWorkbook.Path
    
    ActiveWorkbook.Save
    
    All_Cells_In_All_WorkSheets_1
    ActiveWorkbook.Save
End Sub

RemoveFilters1a code:
Code:
Sub RemoveFilters1a()


    Dim WS As Worksheet


    With Application


        .EnableEvents = False
        .ScreenUpdating = False




        For Each WS In ActiveWorkbook.Sheets


            On Error Resume Next


            WS.ShowAllData


            On Error GoTo 0


        Next


        .EnableEvents = True
        .ScreenUpdating = True


    End With


End Sub

All_Cells_In_All_WorkSheets_1 code:
Code:
Sub All_Cells_In_All_WorkSheets_1()
    Dim sh As Worksheet
    
    Sheets("ImportNonCCB").Visible = True
    Sheets("LKUPs").Visible = True
    
    For Each sh In ActiveWorkbook.Worksheets
        sh.Select
        With sh.UsedRange
            .Cells.Copy
            .Cells.PasteSpecial xlPasteValues
            .Cells(1).Select
        End With
        Application.CutCopyMode = False
    Next sh
    
    Sheets("CC Reconfiguration Data").Range("I3" & LastRow) _
    .Formula = "=VLOOKUP(tblCCReconfig[Control Centre Company Builds],Table6[[Control Centre Company Builds]:[POA GDS]],6,0)"
    
    Sheets("ImportNonCCB").Visible = False
    Sheets("ImportCCBMI").Visible = False
    Sheets("ImportCCB").Visible = False
    Sheets("LKUPs").Visible = False
    Sheets("Instructions").Delete


    
End Sub

any advice gratefully received...this is the final piece of this project and I am done! woo hoo!
 
To save a macro enabled workbook (.xlsm) as a macrodisabled workbook (.xlsx)
Code:
Dim myPath As String
myPath = "C:\DiffDir\"  'You only need this if the path is different than your default path.
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs myPath & "newFileName.xlsx", FileFormat:=51
Application.DisplayAlerts = True
The Display alerts bit will prevent the message telling you that you will lose your macros. See "Workbook.SaveAs Method" in VBA help file.

thanks again for this!
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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