LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Copy Visible Sheets into one Workbook

I need to be able to copy all sheets that are visible (could be 2 sheets to 5
sheets) to a new workbook and give the user the ability to save the file
before closing it. I currently have code to extract one sheet at a time...
but I can't figure out how to put all of them into one workbook. Here's the
code (don't make fun, I've been using VBA for about 6 months) for extracting
a single worksheet. There are links that need to be broken and the print
range needs to be set as well...
Thanks in advance!


Sub ExportSP04cpfReport()
Dim links As Variant
OriginalFileName = Application.ActiveWorkbook.Name
NewFileName = Application.GetSaveAsFilename("SP CPF 04", "Microsoft Excel
(*.xls), *.xls")
If NewFileName = "False" Then
MsgBox "Export Canceled"
Exit Sub
End If
Cells.Select
Selection.Copy
Range("A1").Select
Workbooks.Add
ActiveSheet.Name = "SP CPF 04"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.PageSetup.PrintArea = "$A$1:$AP$54"
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
ActiveWindow.View = xlNormalView
Range("A1").Select
' Define variable as an Excel link type.
links = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLi nks)
' Break the first link in the active workbook.
ActiveWorkbook.BreakLink _
Name:=links(1), _
Type:=xlLinkTypeExcelLinks
'sets print range
Sheets("SP CPF 04").PageSetup.LeftMargin =
Application.InchesToPoints(0.25)
Sheets("SP CPF 04").PageSetup.RightMargin =
Application.InchesToPoints(0.25)
Sheets("SP CPF 04").PageSetup.TopMargin =
Application.InchesToPoints(0.25)
Sheets("SP CPF 04").PageSetup.BottomMargin =
Application.InchesToPoints(0.5)
Sheets("SP CPF 04").PageSetup.CenterHorizontally = True
Sheets("SP CPF 04").PageSetup.Zoom = 90
Sheets("SP CPF 04").Range("A54") = "Exported from Asphalt Plant
Worksheet"
Sheets("SP CPF 04").Protect password:="xxxx"
ActiveWorkbook.SaveAs Filename:=NewFileName _
, FileFormat:=xlNormal, password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I copy just the visible sheets? Trefor Excel Discussion (Misc queries) 2 September 3rd 06 02:31 PM
3 sheets in workbook, but visible only one? slaya_cz Excel Discussion (Misc queries) 3 September 30th 05 01:37 PM
Delete all visible sheets in workbook... Jim Thomlinson[_4_] Excel Programming 2 August 23rd 05 08:04 PM
Delete all visible sheets in workbook... thomas Excel Programming 0 August 23rd 05 07:00 PM
Code to make sheets in a workbook visible Jonsson[_4_] Excel Programming 5 January 30th 04 12:38 PM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"