Paste Special Help

spalton

Board Regular
Joined
Feb 20, 2009
Messages
125
Hi again,

I'm using the following code (from another site) to copy the contents of a worksheet, paste it into a new worksheet and save it. Problem is, it's maintaing the links back to the old workbook, if that is saved, as my users will definitely do I tell them not to, then the values in the saved file will change.

I need to somehow add a 'Paste Special - Values' command into the below somehow, any help greatly appreciated!

Private Sub CommandButton1_Click()
Dim bk As Workbook
Dim fName As Variant
ActiveSheet.Copy
' creates new workbook
Set bk = ActiveWorkbook
fName = Application.GetSaveAsFilename( _
FileFilter:="Excel Files (*.xls), *.xls", _
Title:="Specify Location for Copy:")
If fName = False Then
' user has chosen cancel
' so delete the copy
bk.Close Savechanges:=False
Else
bk.SaveAs fileName:=fName
bk.Close Savechanges:=False
End If
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Think this should do it, please try it on a test copy of your original file in case it overwrites the formula in the wrong sheet!

I'm sure there's a better way of doing it but this should at least give you a "quick fix" if it works. Could be slow depending on the amount of data in the sheet.

Code:
Private Sub CommandButton1_Click()
Dim bk As Workbook
Dim fName As Variant
ActiveSheet.Copy
' creates new workbook
Set bk = ActiveWorkbook
fName = Application.GetSaveAsFilename( _
FileFilter:="Excel Files (*.xls), *.xls", _
Title:="Specify Location for Copy:")
If fName = False Then
' user has chosen cancel
' so delete the copy
bk.Close Savechanges:=False
Else
bk.SaveAs Filename:=fName
 Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
bk.Close Savechanges:=True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,245
Members
448,952
Latest member
kjurney

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