PC Review


Reply
Thread Tools Rate Thread

Add line in existing macro to use template

 
 
Amy
Guest
Posts: n/a
 
      21st Jan 2008
I have a macro that splits one sheet with many pages into individual files by
page numbers using the horizontal page break. It works perfectly. However, I
need it to either A - include the header (and margins) from the original file
when saving to the new file or B - use a template for the new files. I have
tried to use the repeat rows from the first page but that makes a big mess in
the new file. I have copied the macro below. Thanks for the help.

Amy


Sub SplitPages()

Dim horzPBArray()
Dim curWks As Worksheet
Dim newWks As Worksheet
Dim TopRow As Long
Dim i As Long

Set curWks = ActiveSheet
curWks.DisplayPageBreaks = False

ThisWorkbook.Names.Add Name:="hzPB", RefersToR1C1:="=GET.DOCUMENT(64,"""
& ActiveSheet.Name & """)"

ThisWorkbook.Names.Add Name:="vPB", RefersToR1C1:="=GET.DOCUMENT(65,"""
& ActiveSheet.Name & """)"

i = 1
While Not IsError(Evaluate("Index(hzPB," & i & ")"))
ReDim Preserve horzPBArray(1 To i)
horzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
i = i + 1
Wend

ReDim Preserve horzPBArray(1 To i - 1)
Set newWks = Workbooks.Add(1).Worksheets(1)

TopRow = 1
For i = LBound(horzPBArray) To UBound(horzPBArray)
newWks.Cells.Clear
Columns("H:H").ColumnWidth = 13.29
curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
Destination:=newWks.Range("a1")
newWks.Parent.SaveAs Filename:="S:\Amy\Invoices\test\" & "Page" & i,
FileFormat:=xlWorkbookNormal
TopRow = horzPBArray(i)
Next i

newWks.Parent.Close SaveChanges:=False

End Sub

 
Reply With Quote
 
 
 
 
Amy
Guest
Posts: n/a
 
      23rd Jan 2008
My impatience got the best of me... This group is so empowering! Just in case
anyone else could use the info, I have posted back what I figured out to get
everything to work!


Columns("H:H").ColumnWidth = 13.29
Columns("J:J").ColumnWidth = 4.5
curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
Destination:=newWks.Range("a14")
newWks.PageSetup.LeftHeaderPicture.Filename = "S:\Logo
Files\SHINElogoMed.jpg"
newWks.PageSetup.LeftHeader = "&G"
newWks.PageSetup.TopMargin = Application.InchesToPoints(0.08)
newWks.PageSetup.HeaderMargin = Application.InchesToPoints(0.08)
newWks.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.FooterMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.LeftMargin = Application.InchesToPoints(1)
newWks.PageSetup.RightMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.Zoom = 95

"Amy" wrote:

> I have a macro that splits one sheet with many pages into individual files by
> page numbers using the horizontal page break. It works perfectly. However, I
> need it to either A - include the header (and margins) from the original file
> when saving to the new file or B - use a template for the new files. I have
> tried to use the repeat rows from the first page but that makes a big mess in
> the new file. I have copied the macro below. Thanks for the help.
>
> Amy
>
>
> Sub SplitPages()
>
> Dim horzPBArray()
> Dim curWks As Worksheet
> Dim newWks As Worksheet
> Dim TopRow As Long
> Dim i As Long
>
> Set curWks = ActiveSheet
> curWks.DisplayPageBreaks = False
>
> ThisWorkbook.Names.Add Name:="hzPB", RefersToR1C1:="=GET.DOCUMENT(64,"""
> & ActiveSheet.Name & """)"
>
> ThisWorkbook.Names.Add Name:="vPB", RefersToR1C1:="=GET.DOCUMENT(65,"""
> & ActiveSheet.Name & """)"
>
> i = 1
> While Not IsError(Evaluate("Index(hzPB," & i & ")"))
> ReDim Preserve horzPBArray(1 To i)
> horzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
> i = i + 1
> Wend
>
> ReDim Preserve horzPBArray(1 To i - 1)
> Set newWks = Workbooks.Add(1).Worksheets(1)
>
> TopRow = 1
> For i = LBound(horzPBArray) To UBound(horzPBArray)
> newWks.Cells.Clear
> Columns("H:H").ColumnWidth = 13.29
> curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
> Destination:=newWks.Range("a1")
> newWks.Parent.SaveAs Filename:="S:\Amy\Invoices\test\" & "Page" & i,
> FileFormat:=xlWorkbookNormal
> TopRow = horzPBArray(i)
> Next i
>
> newWks.Parent.Close SaveChanges:=False
>
> End Sub
>

 
Reply With Quote
 
Amy
Guest
Posts: n/a
 
      23rd Jan 2008
Just in case anyone can use the information, I figured out exactly what I
needed!

Columns("H:H").ColumnWidth = 13.29
Columns("J:J").ColumnWidth = 4.5
curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
Destination:=newWks.Range("a14")
newWks.PageSetup.LeftHeaderPicture.Filename = "S:\Logo
Files\SHINElogoMed.jpg"
newWks.PageSetup.LeftHeader = "&G"
newWks.PageSetup.TopMargin = Application.InchesToPoints(0.08)
newWks.PageSetup.HeaderMargin = Application.InchesToPoints(0.08)
newWks.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.FooterMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.LeftMargin = Application.InchesToPoints(1)
newWks.PageSetup.RightMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.Zoom = 95

"Amy" wrote:

> I have a macro that splits one sheet with many pages into individual files by
> page numbers using the horizontal page break. It works perfectly. However, I
> need it to either A - include the header (and margins) from the original file
> when saving to the new file or B - use a template for the new files. I have
> tried to use the repeat rows from the first page but that makes a big mess in
> the new file. I have copied the macro below. Thanks for the help.
>
> Amy
>
>
> Sub SplitPages()
>
> Dim horzPBArray()
> Dim curWks As Worksheet
> Dim newWks As Worksheet
> Dim TopRow As Long
> Dim i As Long
>
> Set curWks = ActiveSheet
> curWks.DisplayPageBreaks = False
>
> ThisWorkbook.Names.Add Name:="hzPB", RefersToR1C1:="=GET.DOCUMENT(64,"""
> & ActiveSheet.Name & """)"
>
> ThisWorkbook.Names.Add Name:="vPB", RefersToR1C1:="=GET.DOCUMENT(65,"""
> & ActiveSheet.Name & """)"
>
> i = 1
> While Not IsError(Evaluate("Index(hzPB," & i & ")"))
> ReDim Preserve horzPBArray(1 To i)
> horzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
> i = i + 1
> Wend
>
> ReDim Preserve horzPBArray(1 To i - 1)
> Set newWks = Workbooks.Add(1).Worksheets(1)
>
> TopRow = 1
> For i = LBound(horzPBArray) To UBound(horzPBArray)
> newWks.Cells.Clear
> Columns("H:H").ColumnWidth = 13.29
> curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
> Destination:=newWks.Range("a1")
> newWks.Parent.SaveAs Filename:="S:\Amy\Invoices\test\" & "Page" & i,
> FileFormat:=xlWorkbookNormal
> TopRow = horzPBArray(i)
> Next i
>
> newWks.Parent.Close SaveChanges:=False
>
> End Sub
>

 
Reply With Quote
 
Amy
Guest
Posts: n/a
 
      23rd Jan 2008
Here is what I finally figured out... just in case anyone else can use the
info.




Columns("H:H").ColumnWidth = 13.29
Columns("J:J").ColumnWidth = 4.5
curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
Destination:=newWks.Range("a14")
newWks.PageSetup.LeftHeaderPicture.Filename = "S:\Logo
Files\SHINElogoMed.jpg"
newWks.PageSetup.LeftHeader = "&G"
newWks.PageSetup.TopMargin = Application.InchesToPoints(0.08)
newWks.PageSetup.HeaderMargin = Application.InchesToPoints(0.08)
newWks.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.FooterMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.LeftMargin = Application.InchesToPoints(1)
newWks.PageSetup.RightMargin = Application.InchesToPoints(0.5)
newWks.PageSetup.Zoom = 95

"Amy" wrote:

> I have a macro that splits one sheet with many pages into individual files by
> page numbers using the horizontal page break. It works perfectly. However, I
> need it to either A - include the header (and margins) from the original file
> when saving to the new file or B - use a template for the new files. I have
> tried to use the repeat rows from the first page but that makes a big mess in
> the new file. I have copied the macro below. Thanks for the help.
>
> Amy
>
>
> Sub SplitPages()
>
> Dim horzPBArray()
> Dim curWks As Worksheet
> Dim newWks As Worksheet
> Dim TopRow As Long
> Dim i As Long
>
> Set curWks = ActiveSheet
> curWks.DisplayPageBreaks = False
>
> ThisWorkbook.Names.Add Name:="hzPB", RefersToR1C1:="=GET.DOCUMENT(64,"""
> & ActiveSheet.Name & """)"
>
> ThisWorkbook.Names.Add Name:="vPB", RefersToR1C1:="=GET.DOCUMENT(65,"""
> & ActiveSheet.Name & """)"
>
> i = 1
> While Not IsError(Evaluate("Index(hzPB," & i & ")"))
> ReDim Preserve horzPBArray(1 To i)
> horzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
> i = i + 1
> Wend
>
> ReDim Preserve horzPBArray(1 To i - 1)
> Set newWks = Workbooks.Add(1).Worksheets(1)
>
> TopRow = 1
> For i = LBound(horzPBArray) To UBound(horzPBArray)
> newWks.Cells.Clear
> Columns("H:H").ColumnWidth = 13.29
> curWks.Rows(TopRow & ":" & horzPBArray(i) - 1).Copy
> Destination:=newWks.Range("a1")
> newWks.Parent.SaveAs Filename:="S:\Amy\Invoices\test\" & "Page" & i,
> FileFormat:=xlWorkbookNormal
> TopRow = horzPBArray(i)
> Next i
>
> newWks.Parent.Close SaveChanges:=False
>
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
average Line created in an existing line graph- based on one cell Melanie Microsoft Excel Charting 2 27th Dec 2007 09:14 PM
how to insert text in an existing line w/o adjusting line length =?Utf-8?B?RC4gV3JpZ2h0?= Microsoft Word Document Management 1 1st Aug 2006 07:24 PM
Is there a PowerPoint template/macro that edits existing slides? =?Utf-8?B?c2hhYXphbWluYXRvcg==?= Microsoft Powerpoint 1 8th Feb 2006 05:45 AM
Running a macro to edit one line in existing VBA jbeard@barrick.com.au Microsoft Excel Programming 2 25th Jan 2006 07:45 AM
Re: Storing a created macro into an existing template problem. Larry Microsoft Word New Users 0 31st Jul 2003 06:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:54 PM.