LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Adding a sheet to a workbook

something like following should do what you want.

Sub CopyWorksheetFromTemplate()
Dim wb1 As Excel.Workbook
Dim wb2 As Excel.Workbook
Dim TemplateFile As String
Dim FolderName As String

TemplateFile = "cNotesFile.xlt"

FolderName = "C:\Documents and Settings\Paul\Application
Data\Microsoft\Templates\"

Application.ScreenUpdating = False

Set wb1 = ActiveWorkbook 'Workbooks("cMainWin.xls")


On Error Resume Next
Set wb2 = Workbooks(TemplateFile)
On Error GoTo 0

If wb2 Is Nothing Then

Set wb2 = Workbooks.Open(FolderName & TemplateFile, Editable:=True)

Else

Set wb2 = Workbooks(TemplateFile)

End If

wb2.Worksheets(1).Copy Befo=wb1.Sheets(1)

wb2.Close False

Application.ScreenUpdating = True

End Sub
--
jb


"Paul" wrote:

I have a Development Notes template that I want to add to the front of larger
models that I build.

Having saved the template as a file, I have code that is run from an icon
that should
- identify the activeworkbook
- open the template file
- copy the notes sheet into the activeworkbook
- close the template file

It keeps failing on the second of these two lines, with a 'Subscript out of
range' error

cSheet = Workbooks(cMainWin).Sheets(1).Name
Workbooks(cNotesFile).Worksheets(cNotesFile).Copy
Befo=Workbooks(cMainWin).Sheets(cSheet)

' cNotesFile is the name of the notes template
' cMainWin is the name of the activeworkbook

The first line attempts to get the name of the first sheet in the file (I
originally tried using Sheet(1) but with the same error)

This should be straightforward, but clearly I'm making it more difficult
than it should be - and making it fail at the same time.

Any help would be appreciated

--
If the post is helpful, please consider donating something to an animal
charity on my behalf .......... and click Yes

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a chart to large workbook brings workbook activity to a hal Dale Excel Discussion (Misc queries) 6 December 29th 08 05:50 PM
Adding new work sheet to end of workbook Frank Driscoll Excel Discussion (Misc queries) 3 December 15th 08 05:47 PM
adding a new sheet to a formulated workbook mattshoppe Excel Worksheet Functions 2 February 1st 07 10:43 PM
Macro to prevent adding sheet in a workbook. [email protected] Excel Programming 6 August 15th 06 03:49 AM
Excel, adding figures from one cell to a summary sheet or workbook petercoe Excel Discussion (Misc queries) 5 April 28th 06 01:54 PM


All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"