Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default copy printarea from more than 3 sheet & save in new book.

code is given below which is working for copy printarea
and paste in new workbook with which ever is name
cell "C9" with paste as a value.
but is this copy only sheet1 printarea i want to copy
more than one sheet printarea. I want to copy user
printarea from sheet1, sheet2 & sheet3 and save into new
workbook with which eaver is name in sheet1 cell "C9".

any Help.

Sub testme01()

Dim newWks As Worksheet
Dim myRng As Range
Dim wks As Worksheet
Dim myPrintAddress As String

Set wks = ActiveSheet

myPrintAddress = wks.PageSetup.PrintArea

If myPrintAddress = "" Then
MsgBox "Please set a PrintArea"
Exit Sub
End If

Set newWks = Workbooks.Add(1).Worksheets(1)

wks.Range(myPrintAddress).Copy
'or you could use a built in range name:
'wks.Range("Print_area").Copy

With newWks.Range("a1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
'new in xl2k?
'.PasteSpecial Paste:=xlPasteColumnWidths
End With

With newWks
'range C9 in original worksheet
.Parent.SaveAs FileName:=wks.Range("C9").Value
& " .xls"
'range c9 in the new worksheet
'.Parent.SaveAs Filename:=.Range("C9").Value
& " .xls"
.Parent.Close savechanges:=False
End With

End Sub

****al
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default copy printarea from more than 3 sheet & save in new book.

****al,

Try like:


Sub CopyPA()
Dim wbS As Workbook
Dim wbT As Workbook
Dim w As Worksheet
Dim s As Variant
Dim a As Variant

Set wbS = ActiveWorkbook 'Alternative ThisWorkbook?
a = Array("sheet1", "sheet2", "sheet3")

'Verify PrintAreas
On Error Resume Next
For Each w In wbS.Worksheets(a)
If w.Names("Print_Area") Is Nothing Then s = s & w.Name & vbNewLine
Next
On Error GoTo 0

If Not IsEmpty(s) Then
MsgBox "PrintArea not set in " & vbNewLine & s
Exit Sub
End If

'Create book & sync sheetnames
Set wbT = Workbooks.Add(xlWBATWorksheet)
wbT.Sheets(1).Name = a(0)
For s = 1 To UBound(a)
Set w = wbT.Worksheets.Add(after:=Sheets(Sheets.Count))
w.Name = a(s)
Next

'Store Values in Target
For Each w In wbT.Worksheets
With Range(wbS.Names(w.Name & "!print_area").RefersTo)
.Value = wbS.Names(w.Name & "!print_area").RefersToRange.Value
End With
Next

'Save & Close
wbT.Close True, wbS.Sheets(1).Range("c9").Text

End Sub


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"****al" wrote:

code is given below which is working for copy printarea
and paste in new workbook with which ever is name
cell "C9" with paste as a value.
but is this copy only sheet1 printarea i want to copy
more than one sheet printarea. I want to copy user
printarea from sheet1, sheet2 & sheet3 and save into new
workbook with which eaver is name in sheet1 cell "C9".

any Help.


****al


Reply
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 not copy a sheet to another book dveer Excel Worksheet Functions 7 April 28th 10 03:47 PM
Too Few Rows to copy sheet to another book snowboardbaltimore Excel Worksheet Functions 2 April 19th 10 05:36 PM
Copy a sheet to a new book unsuccessful sunan Excel Discussion (Misc queries) 3 June 23rd 08 12:52 PM
copy the same raws of all sheets from about a 100 file to a new sheet of a book and save the file [email protected] Setting up and Configuration of Excel 0 March 14th 07 02:13 AM
date values change when I copy an excel sheet to a new book man818 Excel Discussion (Misc queries) 4 September 4th 06 09:38 PM


All times are GMT +1. The time now is 10:44 PM.

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

About Us

"It's about Microsoft Excel"