Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Form Data to Excel Workbook

Status
Not open for further replies.

ImSimple

Technical User
Sep 1, 2009
24
0
0
US
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
 
Got the Headings fixed.
Moved

sheet.Range("E31").Select()

above the For Each Statement Duh.

One down :)

Jacque
 
That also fixed the Excel not clearing problem since it is getting to those lines now.

Jacque
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top