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:
  1. Public Sub PrintName(ByVal cont As Control)
  2.  
  3.         Dim xl As New Excel.Application
  4.         Dim wb As Excel.Workbook
  5.         Dim ws As Excel.Worksheet
  6.  
  7.         For Each ctl As Control In cont.Controls
  8.             Application.DoEvents()
  9.  
  10.             wb = xl.Workbooks.Open("C:\Documents and Settings\arichardson\Desktop\controlNames.xls")
  11.             ws = wb.Worksheets.Item(1)
  12.             ws.Cells(1, 1).Value = ctl.Name
  13.             ws.Cells(2, 1).Value = ctl.Parent.Name
  14.             wb.Save()
  15.             wb.Close()
  16.  
  17.             Try
  18.                 If TypeOf ctl Is TabControl Then
  19.  
  20.                     PrintName(ctl)
  21.                 End If
  22.  
  23.                 If TypeOf ctl Is TabPage Then
  24.                     PrintName(ctl)
  25.                 End If
  26.  
  27.                 If TypeOf ctl Is GroupBox Then
  28.                     PrintName(ctl)
  29.                 End If
  30.  
  31.             Catch
  32.  
  33.             End Try
  34.  
  35.         Next
  36.  
  37.  
  38.     End Sub