ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I import an XLT worksheet into another workbook? (https://www.excelbanter.com/excel-programming/341903-how-do-i-import-xlt-worksheet-into-another-workbook.html)

chris5

How do I import an XLT worksheet into another workbook?
 
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.

Myrna Larson

How do I import an XLT worksheet into another workbook?
 
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.

On Tue, 4 Oct 2005 14:34:03 -0700, chris5
wrote:

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.


David Lloyd[_3_]

How do I import an XLT worksheet into another workbook?
 
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
Befo=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.


"chris5" wrote in message
...
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.



Dave Peterson

How do I import an XLT worksheet into another workbook?
 
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")


chris5 wrote:

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.


--

Dave Peterson


All times are GMT +1. The time now is 07:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com