Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Setting sheet.xlt for a workbook programatically

Is there any way to set one particular workbook to use a sheet.xlt template
but still have Excel generally open with a sheet template?

Basically I have a workbook.xlt template that I am using to create a new
workbook through a vb6 program. Once the program is finished running I would
like the user to be able to add a new sheet that has the same formatting as
the workbook.xlt. Is there some property that I can set that will make the
workbook.xlt use the sheet.xlt when creating a new sheet? Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Setting sheet.xlt for a workbook programatically

Try using the NewSheet event:

Delete the sheet the user is creating,
Copy an existing (hidden?) sheet into it's place.

Snippet:
--------------------------------------------------------------------
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim varSheetType As Variant, strShName As String
Application.EnableEvents = False
varSheetType = MsgBox("Do you want to create a new Post Recording
worksheet?", vbYesNoCancel, "Post Log")

Select Case varSheetType
Case vbYes
Application.StatusBar = "Please Wait"
Sheets("Template").Range("A1:I1").Copy Sh.Range("A1:I1")

For c = 1 To 9 Step 1
Sh.Columns(c).ColumnWidth =
Sheets("Template").Columns(c).ColumnWidth
Next c
With Sh.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 85
End With
'Sh.Columns("A:I").AutoFit
With Sh
.Range("A1:I2500").AutoFilter
.Range("B2:IV65536").Locked = False
.Columns("J:IV").Hidden = True
.Range("B2:I1000").ClearContents
[B2].Select
End With
Case vbNo

Case vbCancel
Sh.Delete
End Select
Range("H2:H1000").ClearContents
Application.EnableEvents = True
Application.StatusBar = False
End Sub
--------------------------------------------------------------------

--
HTH
Roger
Shaftesbury (UK)


"trooper665" wrote in message
...
Is there any way to set one particular workbook to use a sheet.xlt
template
but still have Excel generally open with a sheet template?

Basically I have a workbook.xlt template that I am using to create a new
workbook through a vb6 program. Once the program is finished running I
would
like the user to be able to add a new sheet that has the same formatting
as
the workbook.xlt. Is there some property that I can set that will make
the
workbook.xlt use the sheet.xlt when creating a new sheet? Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Setting sheet.xlt for a workbook programatically

Well, I am using the workbook in a vb6 application so if the user decides to
insert a new sheet then the program no longer has focus. Basically I want to
duplicate the functionality of having a Sheet.xlt in the XLStart folder for
only one distinct workbook. I don't want to use this sheet.xlt template at
any other time except when this workbook is open. Is this possible?

"Roger Whitehead" wrote:

Try using the NewSheet event:

Delete the sheet the user is creating,
Copy an existing (hidden?) sheet into it's place.

Snippet:
--------------------------------------------------------------------
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim varSheetType As Variant, strShName As String
Application.EnableEvents = False
varSheetType = MsgBox("Do you want to create a new Post Recording
worksheet?", vbYesNoCancel, "Post Log")

Select Case varSheetType
Case vbYes
Application.StatusBar = "Please Wait"
Sheets("Template").Range("A1:I1").Copy Sh.Range("A1:I1")

For c = 1 To 9 Step 1
Sh.Columns(c).ColumnWidth =
Sheets("Template").Columns(c).ColumnWidth
Next c
With Sh.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 85
End With
'Sh.Columns("A:I").AutoFit
With Sh
.Range("A1:I2500").AutoFilter
.Range("B2:IV65536").Locked = False
.Columns("J:IV").Hidden = True
.Range("B2:I1000").ClearContents
[B2].Select
End With
Case vbNo

Case vbCancel
Sh.Delete
End Select
Range("H2:H1000").ClearContents
Application.EnableEvents = True
Application.StatusBar = False
End Sub
--------------------------------------------------------------------

--
HTH
Roger
Shaftesbury (UK)


"trooper665" wrote in message
...
Is there any way to set one particular workbook to use a sheet.xlt
template
but still have Excel generally open with a sheet template?

Basically I have a workbook.xlt template that I am using to create a new
workbook through a vb6 program. Once the program is finished running I
would
like the user to be able to add a new sheet that has the same formatting
as
the workbook.xlt. Is there some property that I can set that will make
the
workbook.xlt use the sheet.xlt when creating a new sheet? Thanks




Reply
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
Setting a cell reference in one sheet that updates a workbook? Danhalawi Excel Discussion (Misc queries) 1 November 7th 06 04:08 PM
programatically retrieve selected rows from excel workbook talktobatchu Excel Programming 0 June 1st 05 10:15 PM
Programatically sending a sheet through Outlook Mark Scott[_4_] Excel Programming 11 February 10th 05 05:04 PM
Programatically saving workbook (or worksheet) without the code Hugh Excel Programming 4 October 22nd 04 12:03 AM
Copy Worksheet to another workbook, programatically? plh[_2_] Excel Programming 5 August 13th 03 08:12 PM


All times are GMT +1. The time now is 11:42 AM.

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

About Us

"It's about Microsoft Excel"