CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    4

    [RESOLVED] Copy Sheet & Name checkbox.text

    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
    Code:
    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
    Last edited by Shuja Ali; September 11th, 2009 at 01:54 PM. Reason: Added code tags

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Copy Sheet & Name checkbox.text

    Please use code tags to make your code better legible.
    Also it seems to be VB.NET, so you are rather wrong here.

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Copy Sheet & Name checkbox.text

    [Moved to VB.NET]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured