Subscribe to this feed

Navigation

Recent Posts

Archive

Excel macro to copy to Custom Template

Saturday 18 Aug, 2007 - 09:50am | 0 comments |

The following macro copies an Excel sheet to a custom template. All you need do is set the template path to your own or a network drive. This is really only a snippet to demonstrate the concept but is a complete macro nonetheless. I've used it within a more complex process to generate invoices from a data file, then copy each invoice to a separate file to email out as an attachment. This was a temporary solution during the lead up to a billing system change for a Telecoms client. 

I've used this to get around not being able to copy headers and footers in Excel and to avoid copying common drawing objects such as a logo and text boxes. By having these set in the template I didn't need to copy them each time the process looped.

Sub copy_ActiveSheet()
Dim wb As Workbook
Dim source As Range
Dim dest As Workbook

'Enter the path to your template file
Const TemplatePath As String = "C:mark.xlt"

Set source = Nothing
On Error Resume Next
Set source = Cells.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

Application.ScreenUpdating = False
Set dest = Workbooks.Add(TemplatePath)
source.Copy
With dest.Sheets(1)
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
End With

Tags: Excel |Macro |Drawing objects |headers |footers

Add a comment
 | Link | Back to top | del.icio.us digg it furl reddit
Previous Next

© Eriginal Ltd 2011, all rights reserved