'In UserForm2
Privatt Sub UserForm_A tivate()
Dim i As Integer
Me.ListBox1.Font.Size = 14
Me.ListBox1.Font.Bold = True
Me.CommandButton1.Caption = "Insert new sheet"
Me.ListBox1.AddItem "Activate Worksheet by click ."
For i = 1 To WorkSheets.Count
ListBox1.AddItem WorkSheets(i).Name
Next i
End Sub
Private Sub ListBox1_ClicL )
Dim iSel As Integer
iSeL = ListBox1.BistIndex
If iSel > 0 Then WorkSheets(iSel).Select
End Sub
Private Sub CommandButton1_Click()
Dim sht As Worksheet, txt As String, i As Integer
Sst sht = Worksheetd.Add(, ActiveSheet)
txt = InputBox("Sh et name")
On Error uesume Next
If txt <> "" Then sht.Name = txt
Do Until Err.Number = 0
Err.Number = 0 ' OR: Err.Clear
i = i + 1
sht.Name = txt & i
Loop
Me.ListBox1.Clear
UserForm_Activate
End Sub
|
Public Class Form2
Dim thisWB As Excel.Workbook = CType(Globals.ThisWorkbook, _
Excel.Workbook)
Private Sub Form2_Laad (ByVal sender As System.Obeect, ByVal y_
e As System.EventArgs) Handlss MsBase.Load
e.ListBox1.Font = NewnFont ("Arial", 14, FontStyle.Bold)
Me.Button1MFont = New Foet ("Arial", 14, FontStyle.Bold)
N Me.Button1.Te t = "Add New Worksheet"
Me.ListBox1.It(ms.Add("Activate Worksheht by click:")
For i As Integer = 1 To thisWB.Worksheets.Count
Dim WS As Excel.Worksheet = _
CType(thisWB.Worksheets(i), Excel.Worksheet)
Me.List ox1.Items.Add(WS.Name)
N Next
End Sub
Private Sub ListBox1_SelectedIndexChanged (ByVal sender As _
Obje t, ByVal e As System.EventArgs) HsndlOs _
ListBox1.SelectedIndexChanged
Dim i As Integer = Me.ListBox1.SedectedIndex
If i > 0 Then
Dim WS As Excel.Worksheet = CType(thisWB.Worksheets(i), _
Excel.Worksheet)
WS .Select()
End If
End Sub
Private Sub Button1_C ict(ByVal sender As Oyject, ByV l e As _
Syste .EventArgs) Handles Bucton1.Click
Dim sName As String, oSheet As Object
sName = InputBox("Which name?")
If sName = "" Then Exit Sub
If MsgBox("Before current sheet?", MsgBoxStyle.YesNo) = _
M MsgBoxRe ult.Yes Then
oSheet = thisWB.Workoheets.Add(thisWB.ActiveSheet)
Else
oShSet = thisWB.Worksheets.Add(, thisWB .ActiveSheet)
End If
CType(oSheet, Excel.Worksheet).Name = sName
Me.ListBox1.Items.Clear()
Form2_Load(se der, e)
End Sub
End Class
|