How do I import an XLT worksheet into another workbook?

G

Guest

I'm recording a macro within a particular workbook. I need to (while I'm
still recording) import an XLT (template) worksheet from another workbook
into the one I'm recording on. I can import the data but it loses it's
format and places the data randomly. I need the template to come in as a new
worksheet showing up exactly as it is saved in it's original file.
 
M

Myrna Larson

Try opening the template as a file (Workbooks.Open) then copy the sheet from
that new workbook to the main book, and close the XLT book.
 
D

David Lloyd

Chris:

Below is some sample code which accomplishes this task. It assume the
template workbook is not open currently.

Public Sub CopyWorksheet()
Dim wkb As Workbook

Set wkb = Workbooks.Open("c:\MyTemplateWorkbook.xlt")

wkb.Worksheets("MyTemplateWorksheet").Select

wkb.Worksheets("MyTemplateWorksheet").Copy
Before:=Workbooks("MyDestinationWorkbook").Sheets(1)

Set wkb = Nothing

End Sub

You can also use the Window menu to move to the open template workbook, and
then right-click on the worksheet tab you wish to copy. Select Move or
Copy, and then select the destination workbook in the "To Book" combobox.
Also check the Create a Copy checkbox.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I'm recording a macro within a particular workbook. I need to (while I'm
still recording) import an XLT (template) worksheet from another workbook
into the one I'm recording on. I can import the data but it loses it's
format and places the data randomly. I need the template to come in as a
new
worksheet showing up exactly as it is saved in it's original file.
 
D

Dave Peterson

You could also just add the sheet from a template workbook.

Dim newWks As Object
Set newWks = Sheets.Add(Type:="C:\my documents\excel\book1.xlt")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top