|
-
Apr 23rd, 2004, 10:31 AM
#1
Thread Starter
Frenzied Member
excel cells
when saving data to an excel worksheet, you reference the cell by coordinates: .cells(1,1) for ex.
IF you can't use a variable to increment because you are in a recursive loop, how do you save to the next cell?
VB Code:
Public Sub PrintName(ByVal cont As Control)
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
For Each ctl As Control In cont.Controls
Application.DoEvents()
wb = xl.Workbooks.Open("C:\Documents and Settings\arichardson\Desktop\controlNames.xls")
ws = wb.Worksheets.Item(1)
ws.Cells(1, 1).Value = ctl.Name
ws.Cells(2, 1).Value = ctl.Parent.Name
wb.Save()
wb.Close()
Try
If TypeOf ctl Is TabControl Then
PrintName(ctl)
End If
If TypeOf ctl Is TabPage Then
PrintName(ctl)
End If
If TypeOf ctl Is GroupBox Then
PrintName(ctl)
End If
Catch
End Try
Next
End Sub
-
May 5th, 2004, 02:25 PM
#2
Frenzied Member
Andy ...
Did you ever get this solved? Why do you bang the workbook for every control? Why not just open it BEFORE iterating the controls, load the cells using index variables, and then save the workbook after all the controls are processed. I can help with this one ... I iterate through Excel sheets all the time. Let me know if you are still working on it.
By the way, Thank you for the concise example of getting into an Excel sheet ... I'm a VB.Net Newbie.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|