Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ram Ram is offline
external usenet poster
 
Posts: 138
Default Move / copy worksheet without any changes to the page setup

Hi,

I've got code to copy worksheets as individual files, however, once the code
is executed and i've got individual files, the page setup is not the same as
the original.

code is below

Sub TEST()
Dim NB, MB As Workbook
Set MB = ThisWorkbook
Dim I, II As Long
For I = 1 To MB.Sheets.Count
Set NB = Workbooks.Add
MB.Sheets(I).Cells.Copy NB.Sheets(1).Range("A1")
NB.Sheets(1).Name = MB.Sheets(I).Name
For II = 2 To NB.Sheets.Count
Application.DisplayAlerts = False
NB.Sheets(2).Delete
Application.DisplayAlerts = True
Next
ActiveWindow.DisplayGridlines = False
NB.SaveAs "C:" & MB.Sheets(I).Name & ".xls"
NB.SendMail ", "Split files"
NB.Close
Next
End Sub

Can you help add a code here which will retain the page setup (page
orientation and margins)

Also, instead of sending email, is it possible to just save the emails in
drafts folder?

thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Move / copy worksheet without any changes to the page setup

Your code doesn't really copy the worksheets from the master workbook--it copies
the cells in each sheet to a newly created workbook/worksheet.

You have a couple of choices.

You could go through the page setup for the new sheet and make them match the
page setup of the sending sheet. You have to do it for each setting that you
want to keep.

The other option is to copy the sheet to the new workbook--essentially going
through the Edit|Move or copy dialog. This way all the settings will travel
with the worksheet--the rowheight, columnwidths, filters, print layout,
shapes/buttons, and code behind the sheet (worksheet events or code for controls
from the control toolbox toolbar).

If you want to try the second option:

Option Explicit
Sub TEST2()

Dim NB As Workbook
Dim MB As Workbook
Dim I As Long

Set MB = ThisWorkbook

For I = 1 To MB.Sheets.Count
'add a single sheet workbook
Set NB = Workbooks.Add(template:=xlWBATWorksheet)
NB.Worksheets(1).Name = "deletemelater"

MB.Sheets(I).Copy _
after:=NB.Worksheets(1)

Application.DisplayAlerts = False
NB.Worksheets("deletemelater").Delete
Application.DisplayAlerts = True

'not c:\ ?????
NB.SaveAs "C:" & MB.Sheets(I).Name & ".xls"
NB.SendMail ", "Split files"
NB.Close savechanges:=False
Next I
End Sub

ps.
Dim NB, MB As Workbook
declares NB as a variant and MB as a workbook

Same with:
Dim I, II As Long
I is a Variant, II is long.

You could use:

Dim NB as workbook, mb as workbook
dim i as long, ii as long

======
You may want to include what email client you're using to send/save as draft.
It may help others help you.


Ram wrote:

Hi,

I've got code to copy worksheets as individual files, however, once the code
is executed and i've got individual files, the page setup is not the same as
the original.

code is below

Sub TEST()
Dim NB, MB As Workbook
Set MB = ThisWorkbook
Dim I, II As Long
For I = 1 To MB.Sheets.Count
Set NB = Workbooks.Add
MB.Sheets(I).Cells.Copy NB.Sheets(1).Range("A1")
NB.Sheets(1).Name = MB.Sheets(I).Name
For II = 2 To NB.Sheets.Count
Application.DisplayAlerts = False
NB.Sheets(2).Delete
Application.DisplayAlerts = True
Next
ActiveWindow.DisplayGridlines = False
NB.SaveAs "C:" & MB.Sheets(I).Name & ".xls"
NB.SendMail ", "Split files"
NB.Close
Next
End Sub

Can you help add a code here which will retain the page setup (page
orientation and margins)

Also, instead of sending email, is it possible to just save the emails in
drafts folder?

thanks in advance


--

Dave Peterson
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
How to copy page setup Robin Chapple New Users to Excel 2 July 30th 06 05:05 PM
Copy Page Setup across tabs JWF Excel Discussion (Misc queries) 1 March 13th 06 04:04 PM
copy page setup from worksheet to another within workbook Fanny Excel Worksheet Functions 2 October 6th 05 02:49 AM
Can I copy a worksheet with its page setup and print formats? MSSAC_QA Excel Discussion (Misc queries) 2 July 14th 05 02:24 PM
How do I copy page setup from one worksheet & paste into new shee. Rasc0 Excel Discussion (Misc queries) 2 December 1st 04 10:12 PM


All times are GMT +1. The time now is 04:49 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"