Saving a worksheet in a new workbook as values only?

Cuzzaa

Board Regular
Joined
Apr 30, 2019
Messages
86
Hi everyone

Really hope a genius could help me :)

I'm using the code below in a command button to save a particular worksheet in a new workbook, however I am trying to achieve 2 things, please could someone help me?

1) How do I only paste as values only but while also retaining the formatting of colours, borders etc?
2) Instead of saving in a particular folder by default and saving as "BOM.xlsx", how can I change this to instead prompt the user WHERE to save and WHAT to call the new workbook?

Code:
Sub ExporthisBOM()    Dim wb As Workbook
    Set wb = Workbooks.Add
    ThisWorkbook.Sheets("BOM Export").Copy Before:=wb.Sheets(1)
    wb.SaveAs "C:\Users\Folder\BOM.xlsx"
End Sub

Thanks so much for any help and guidance!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try:
Code:
Sub ExporthisBOM()
    Dim fName
    Sheets("BOM Export").Copy
    With ActiveSheet
        .UsedRange.Copy
        .Cells(1, 1).PasteSpecial xlPasteValues
        .Cells(1, 1).PasteSpecial xlPasteFormats
    End With
    Application.CutCopyMode = False
    fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Save As")
    ActiveWorkbook.SaveAs Filename:=fName
End Sub
 
Upvote 0
Try:
Code:
Sub ExporthisBOM()
    Dim fName
    Sheets("BOM Export").Copy
    With ActiveSheet
        .UsedRange.Copy
        .Cells(1, 1).PasteSpecial xlPasteValues
        .Cells(1, 1).PasteSpecial xlPasteFormats
    End With
    Application.CutCopyMode = False
    fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Save As")
    ActiveWorkbook.SaveAs Filename:=fName
End Sub

Thank you Mumps!

There is just one thing, when I click on the button now it says 'There is already data here. Do you wish to replace it?' once it opens the new worksheet and pastes the data into it.

Have you any idea why it's doing this and how to make it not do this?
 
Upvote 0
Does the file you are saving already exist in the folder that you select and therefore it asks if you want to replace it?
 
Upvote 0
Does the file you are saving already exist in the folder that you select and therefore it asks if you want to replace it?

It's ok I fixed it, it was trying to paste a merged cell and didn't like it so I removed and now it's working as expected.

Just one quick question, is there a way to automatically close the newly saved workbook once you've named it and saved it so it doesn't stay open?

Thanks again mate
 
Upvote 0
Try:
Code:
Sub ExporthisBOM()
    Dim fName
    Sheets("BOM Export").Copy
    With ActiveSheet
        .UsedRange.Copy
        .Cells(1, 1).PasteSpecial xlPasteValues
        .Cells(1, 1).PasteSpecial xlPasteFormats
    End With
    Application.CutCopyMode = False
    fName = Application.GetSaveAsFilename(InitialFileName:="", FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Save As")
    With ActiveWorkbook
        .SaveAs Filename:=fName
        .Close False
    End With
End Sub
When responding, please click the "Reply" button instead of the "Reply With Quote" button. This helps to remove unnecessary clutter. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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