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




Reply With Quote