if possible, I would like a way to generate a template
You can save spreadsheets as templates (I'm not an expert on this) - that may do what you want.
As far as doing what you have asked, I know where to begin, but not where to end! To literally replicate .copy would probably involve dozens (maybe hundreds!) of parameters that hardly anyone has heard of or even used. If the formatting is fairly simple then it shouldn't be too hard to come up with something, but if there is anything like a cell that has more than one font size or colour in it, then things start getting messy.
Anyway - if you really want to try it, this might get you started. The code below writes the address, value, formula, and a few other things for every cell to a .txt file.
Option Explicit
Public Sub CopyAll()
Dim Cell As Range
Dim FNum As Long
FNum = FreeFile
Open ThisWorkbook.Path & "\Template.txt" For Output As #FNum
For Each Cell In ActiveSheet.UsedRange.Cells
Print #FNum, Cell.Address & "|" & Cell.Value & "|" & Cell.Formula & "|" & Cell.Font.Color & "|" & Cell.Font.Bold & "|" & Cell.Font.Italic & "|" & Cell.Interior.ColorIndex & "|" & Cell.Interior.Color
Next
Close FNum
End Sub
And this reads from the file and applies it to the spreadsheet.
Public Sub CreateFromTemplate()
Dim Cell As Range
Dim FNum As Long, x As Long
Dim Info As String
Dim Records() As String, Record() As String
FNum = FreeFile
Open ThisWorkbook.Path & "\Template.txt" For Binary As #FNum
Info = Space(LOF(FNum))
Get #FNum, , Info
Close FNum
Records = Split(Info, vbCrLf)
For x = 0 To UBound(Records) - 1
Record = Split(Records(x), "|")
Set Cell = Range(Record(0))
With Cell
.Value = Record(1)
If Not Records(1) = vbNullString Then .Formula = Record(2)
.Font.Color = Record(3)
.Font.Bold = Record(4)
.Font.Italic = Record(5)
.Interior.ColorIndex = Record(6)
If Not Record(6) = xlNone Then .Interior.Color = Record(7)
End With
Next
End Sub
Bookmarks