![]() |
Inserting a worksheet based on a template
Hi jstrater
Try something like this Sub test() Dim MyPath As String Dim SaveDriveDir As String Dim FileToOpen As Variant SaveDriveDir = CurDir MyPath = Application.TemplatesPath ChDrive MyPath ChDir MyPath FileToOpen = Application.GetOpenFilename("Excel Templates (*.xlt),*.xlt") If FileToOpen < False Then Sheets.Add Type:=FileToOpen End If ChDrive SaveDriveDir ChDir SaveDriveDir End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "jstrater" wrote in message ... I do this all the time by right clicking on a sheet tab and selecting a template in the Insert Sheet dialog. But I don't see a way to do this from code. The Sheets and Worksheets.Add method doesn't have a place to specify a template file name, and I don't see any other methods for doing this. Is this just a glaring omission, or am I missing something? I'm using Excel XP (and sometimes Excel 97) --- James |
Inserting a worksheet based on a template
Of course this will also work
Sheets.Add Type:=Application.TemplatesPath & "\xxxxx.xlt" -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi jstrater Try something like this Sub test() Dim MyPath As String Dim SaveDriveDir As String Dim FileToOpen As Variant SaveDriveDir = CurDir MyPath = Application.TemplatesPath ChDrive MyPath ChDir MyPath FileToOpen = Application.GetOpenFilename("Excel Templates (*.xlt),*.xlt") If FileToOpen < False Then Sheets.Add Type:=FileToOpen End If ChDrive SaveDriveDir ChDir SaveDriveDir End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "jstrater" wrote in message ... I do this all the time by right clicking on a sheet tab and selecting a template in the Insert Sheet dialog. But I don't see a way to do this from code. The Sheets and Worksheets.Add method doesn't have a place to specify a template file name, and I don't see any other methods for doing this. Is this just a glaring omission, or am I missing something? I'm using Excel XP (and sometimes Excel 97) --- James |
Inserting a worksheet based on a template
Ron,
You seem to be omnipresent here in the world of Excel programming. So the Type parameter is more maleable than the documentation mentions. That's great. Thanks. James |
All times are GMT +1. The time now is 09:51 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com