Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro to copy sheet and name it

Status
Not open for further replies.

Mturner

IS-IT--Management
Jan 15, 2001
288
0
0
GB
HI all, this is probally a very easy one for anyone who knows anything about excel, unfourtunatly i dont use it much.
basicly i have designed a spread sheet, what i would like to do is make a button to create a copy of it, so its a new workbook, and ask the user what to name it.
so basicly i need a button to say new sheet, then a dialogue box to appear asking for a name.....any ideas??

many thanks

Marc
 
Maybe just saving this workbook as a template would work for you...

'**************************


Create a workbook template for new workbooks
Create a workbook that contains the sheets, default text (such as page headers and column and row labels), formulas, macros, styles, and other formatting you want in new workbooks that you base on the template.


On the File menu, click Save As.
Show Me

In the Save as type box, click Template (*.xlt).


In the Save in box, select the folder where you want to store the template.
To create the default workbook template, select either the XLStart folder or the alternate startup folder. The XLStart folder is usually
C:\os\Profiles\user_name\Application Data\Microsoft\Excel\XLStart
where os is the operating system folder — for example, Windows.

To create a custom workbook template, select the Templates folder, which is usually
C:\os\Profiles\user_name\Application Data\Microsoft\Templates
where os is the operating system folder, for example, Windows.

In the File name box, type book to create a default workbook template.
To create a custom template, type any valid file name.

Tip To display a picture of the first page of a template in the Preview box of the New dialog box (File menu), click Properties on the File menu, click the Summary tab, and then select the Save preview picture check box.




 
thanks for replying, i dont want loads of diffrent files though, i want multiple sheets in one file if you get my drift.
Many thanks

marc
 
Ok...then turn on the macro recorder

and step through the process of copying the sheet to another workbook

stop the recorder whren complete.

then create a button from the forms toolbar and link the macro to the button.
 
thats what i thought, but will that ask the user for a name for the new sheet?
 
If you need to rename the new sheet then add that step to the recorded process then you can edit it to name the sheet via code or via an inputbox prompt to the user.


'***********
Sheets("Sheet1").Copy Before:=Workbooks("Book2").Sheets(1)
Sheets("Sheet1 (2)").Name = inputbox("Enter sheet name")
Windows("auto_cal.xls").Activate
'***********


note:Sheets("Sheet1 (2)") may change depending on sheet names already established in the copy to workbook.
 
It's actually even simpler than that

Sheets("Sheetname").copy
activeworkbook.activesheet.name = inputbox("Enter Sheet Name")

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
thank you all very much for your responces, all have been very helpful and the spreadsheet now does exactly what i want it too!

cheers

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top