View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Export Sheet Values to new workbook

You might want to know that in this scenario wksSource wasn't really
necessary since we could do this:

Set wkbTarget = Sheets("overview").Copy

...then do whatever with wkbTarget.

My point for using wksSource is that in some cases the formula refs may
result in unexpected behavior when copied to a new wkb and so may
require copying to the source wkb, convert formula results to constant
values, then Move the sheet into wkbTarget. So then...

Sub CopyOverview()
Dim wksSource As Worksheet, wkbTarget As Workbook
Dim SaveAsFilename As String, sWksName As String

SaveAsFilename = ThisWorkbook.Path & "\Overview-" _
& FileNameDateString(IncludeNone) & ".xls"
sWksName = Sheets("overview").Name

Set wksSource = Sheets("overview").Copy After:=Sheets("overview")
With wksSource
.UsedRange.Value = .UsedRange.Value
End With

Set wkbTarget = wksSource.Move
With wkbTarget
.Sheets(1).Name = sWksName
.SaveAs SaveAsFilename: .Close
End With
End Sub

After which you're returned to the source wkb which should be closed
without saving changes. If you're done with it after running the
CopyOverview procedure then you can incorporate that into the process.

Add var:
Dim wkbSource As Workbook
Set wkbSource = ActiveWorkbook

At the end of the proc:
wkbSource.Close SaveChanges:=False

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc