View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
William[_2_] William[_2_] is offline
external usenet poster
 
Posts: 227
Default Add Sheet - Copy Worksheet

Hi

Firstly, create your 4 templates - they should consist of one sheet each.
Save them to the same location where the current workbook that will execute
the code is located. Name the templates "wb1.xlt", "wb2.xlt", "wb3,xlt" and"
wb4.xlt".

Secondly, copy the code below into a general module of your workbook.

To create the buttons on a worksheet, run the macro "ButtonsOnWorksheet" - I
have assumed the sheet on which you want the buttons places is called
"MySheet" - change the worksheet name in the macro code as appropriate.

Sub ButtonsOnWorksheet()
Dim b As Button, t As Long, h As Long
Dim l As Long, w As Long
With ThisWorkbook.Sheets("MySheet")
t = 0
h = 0
l = 95
w = 21
Set b = .Buttons.Add(t, h, l, w)
..DrawingObjects.Delete
Set b = .Buttons.Add(t, h, l, w)
b.OnAction = ThisWorkbook.Name & "!getbook1"
b.Characters.Text = "Book 1"
t = t + l + 10
Set b = .Buttons.Add(t, h, l, w)
b.OnAction = ThisWorkbook.Name & "!getbook2"
b.Characters.Text = "Book 2"
t = t + l + 10
Set b = .Buttons.Add(t, h, l, w)
b.OnAction = ThisWorkbook.Name & "!getbook3"
b.Characters.Text = "Book 3"
t = t + l + 10
Set b = .Buttons.Add(t, h, l, w)
b.OnAction = ThisWorkbook.Name & "!getbook4"
b.Characters.Text = "Book 4"
End With
End Sub

Sub getbook1()
Dim wb As Workbook, ws As Worksheet, i As Integer
Set wb = ThisWorkbook
wb.Sheets.Add Type:=ThisWorkbook.Path & "\wb1.xlt"
i = wb.Sheets.Count
Set ws = ActiveSheet
ws.Move After:=wb.Sheets(i)
End Sub

Sub getbook2()
Dim wb As Workbook, ws As Worksheet, i As Integer
Set wb = ThisWorkbook
wb.Sheets.Add Type:=ThisWorkbook.Path & "\wb2.xlt"
i = wb.Sheets.Count
Set ws = ActiveSheet
ws.Move After:=wb.Sheets(i)
End Sub

Sub getbook3()
Dim wb As Workbook, ws As Worksheet, i As Integer
Set wb = ThisWorkbook
wb.Sheets.Add Type:=ThisWorkbook.Path & "\wb3.xlt"
i = wb.Sheets.Count
Set ws = ActiveSheet
ws.Move After:=wb.Sheets(i)
End Sub

Sub getbook4()
Dim wb As Workbook, ws As Worksheet, i As Integer
Set wb = ThisWorkbook
wb.Sheets.Add Type:=ThisWorkbook.Path & "\wb4.xlt"
i = wb.Sheets.Count
Set ws = ActiveSheet
ws.Move After:=wb.Sheets(i)
End Sub



--

-----
XL2002
Regards

William




"ckrogers" wrote in message
...
I'd like to add four buttons to a worksheet. When any of the buttons are
clicked, a sheet will be added (to the end) of a workbook. Then,
depending
on which button is clicked, one of four worksheet templates will be copied
onto the new sheet. The four templates could either be four separate
files,
or they could be separate sheets in one file ... whichever works
better/easier....
Help, please!
Cindy