I'm having multiple problems with this. Everytime I think I'm making progress I take 7 steps back. I'm running in circles.
ANY help is greatly appreciated. Here's the whole thing with comments on the problems.
Imports Microsoft.Office.Interop
Public Class ScopeSheetBuilder
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim sheets As Microsoft.Office.Interop.Excel.Worksheets
Dim sheet As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Add("F:\Work Stuff\Scope Sheet Creator\Scope Sheet Template.xlt")
sheet = wb.Worksheets("Template")
excel.Visible = True
excel.UserControl = True
'SHEETS
For Each ctrl As Control In Me.Controls
If (TypeOf ctrl Is CheckBox AndAlso CType(ctrl, CheckBox).Checked) AndAlso CType(ctrl, CheckBox).Name.Contains("Sheet") Then
wb.Worksheets("Template").copy(after:=sheet)
sheet = wb.ActiveSheet
sheet.Name = CType(ctrl, CheckBox).Text
'ADD GENERAL ITEMS
'ADD PROJECT INFO
'HEADINGS *******ONLY CATCHING 1ST HEADING ON EACH SHEET*******
For Each head As Control In Me.Controls
If (TypeOf head Is CheckBox AndAlso CType(head, CheckBox).Checked) AndAlso CType(head, CheckBox).Name.Contains("Head" & sheet.Name) Then
sheet.Range("E31").Select()
excel.ActiveCell.Value2 = CType(head, CheckBox).Text
'LINE RETURN
excel.ActiveCell.Offset(+1, 0).Select()
'ITEMS
For Each box As ListBox In Me.Controls
If box.Name.Contains(head.Name) Then
Dim itms As ListBox.SelectedObjectCollection
itms = box.SelectedItems
excel.ActiveCell.Value2 = itms
excel.ActiveCell.Offset(+1, 0).Select()
End If
Next
End If
Next
End If
Next
excel = Nothing
wb = Nothing
sheet = Nothing
sheets = Nothing
rng = Nothing
End Sub
Jacque
ANY help is greatly appreciated. Here's the whole thing with comments on the problems.
Imports Microsoft.Office.Interop
Public Class ScopeSheetBuilder
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim sheets As Microsoft.Office.Interop.Excel.Worksheets
Dim sheet As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Add("F:\Work Stuff\Scope Sheet Creator\Scope Sheet Template.xlt")
sheet = wb.Worksheets("Template")
excel.Visible = True
excel.UserControl = True
'SHEETS
For Each ctrl As Control In Me.Controls
If (TypeOf ctrl Is CheckBox AndAlso CType(ctrl, CheckBox).Checked) AndAlso CType(ctrl, CheckBox).Name.Contains("Sheet") Then
wb.Worksheets("Template").copy(after:=sheet)
sheet = wb.ActiveSheet
sheet.Name = CType(ctrl, CheckBox).Text
'ADD GENERAL ITEMS
'ADD PROJECT INFO
'HEADINGS *******ONLY CATCHING 1ST HEADING ON EACH SHEET*******
For Each head As Control In Me.Controls
If (TypeOf head Is CheckBox AndAlso CType(head, CheckBox).Checked) AndAlso CType(head, CheckBox).Name.Contains("Head" & sheet.Name) Then
sheet.Range("E31").Select()
excel.ActiveCell.Value2 = CType(head, CheckBox).Text
'LINE RETURN
excel.ActiveCell.Offset(+1, 0).Select()
'ITEMS
For Each box As ListBox In Me.Controls
If box.Name.Contains(head.Name) Then
Dim itms As ListBox.SelectedObjectCollection
itms = box.SelectedItems
excel.ActiveCell.Value2 = itms
excel.ActiveCell.Offset(+1, 0).Select()
End If
Next
End If
Next
End If
Next
excel = Nothing
wb = Nothing
sheet = Nothing
sheets = Nothing
rng = Nothing
End Sub
Jacque