Click to See Complete Forum and Search --> : [RESOLVED] Copy Sheet & Name checkbox.text


jacqjac
September 10th, 2009, 05:07 PM
I am trying to use a vb window app to open an existing excel workbook, and for every checkbox that is checked on the form copy the existing worksheet and name it with the text of the checkbox when the button is clicked

Please help

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
excel = New Microsoft.Office.Interop.Excel.Application
'sheets = New Microsoft.Office.Interop.Excel.Worksheet
wb = excel.Workbooks.Add("F:\Work Stuff\Scope Sheet Creator\Scope Sheet Template.xlt")
excel.Visible = True
wb.Activate()

For Each ctrl As Control In Me.Controls
If (TypeOf ctrl Is CheckBox AndAlso CType(ctrl, CheckBox).Checked) Then
wb.Sheets("Template").activate()
wb.Sheets("Template").select()
wb.Sheets("Template").copy(after:=sheets.Count, Name:=CStr(ctrl.Text)) 'error use new

End If
Next
excel = Nothing
wb = Nothing
End Sub

WoF
September 11th, 2009, 08:26 AM
Please use code tags to make your code better legible.
Also it seems to be VB.NET, so you are rather wrong here.

Shuja Ali
September 11th, 2009, 01:55 PM
[Moved to VB.NET]