我想将MS Excel中的一个特定工作表复制到一个新文件中。以下宏执行此任务,但问题是副本始终将单元格链接到原始文件。有没有办法只插入没有链接的这个工作表的值?
Sub Copy_sheet()
ThisWorkbook.Sheets("Overview").Copy
ActiveWorkbook.SaveAs "C:\testfolder\testfile.xlsx", FileFormat:=51
End Sub
谢谢!
答案 0 :(得分:2)
在End sub
:
With ThisWorkbook.Worksheets("Overview").UsedRange
.Value = .Value
End With
它会将公式更改为值。如果您想为整个工作簿执行此操作,则可以采用以下方法:
Public Sub CopyJustData()
Dim lngCount As Long
For lngCount = 1 To Worksheets.Count
With Worksheets(lngCount).UsedRange
.Value = .Value
End With
Next lngCount
End Sub
答案 1 :(得分:0)
一种方法就是这样。
Sub Copy_sheet()
Dim wbNew As Workbook
ThisWorkbook.Sheets("Overview").Copy
Set wbNew = ActiveWorkbook
With wbNew
With .Worksheets(1).UsedRange
.Value = .Value
End With
.SaveAs "C:\testfolder\testfile.xlsx"
End With
End Sub
答案 2 :(得分:0)
Sub SaveCopy
ThisWorkbook.Sheets("your sheet name").Select
ActiveSheet.Copy
ActiveSheet.SaveAs FileName:="your path to save "& ".xlsx" 'xlsx or your other
BreakLinks '
End Sub
Sub BreakLinks()
On Error Resume Next
Dim vLinks As Variant
Dim lLink As Long
' Define variable as an Excel link type.
vLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
If vLinks = vbNullString Then Exit Sub
' Break all links in the active workbook.
For lLink = LBound(vLinks) To UBound(vLinks)
ActiveWorkbook.BreakLink _
Name:=vLinks(lLink), _
Type:=xlLinkTypeExcelLinks
Next lLink
End Sub