CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Posts
    72

    can i enter data in excel thru vb?

    can i enter rows of data/ add spreadsheets to my excel file thru vb?


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: can i enter data in excel thru vb?

    you can use OLE automation to do that.
    Add a reference to the Excel Typelibrary to your vb project and adopt the following sample (passes listview data to excel)

    private Sub Command1_Click()
    Dim i as ListItem
    Dim j as Integer
    for j = 1 to 5
    set i = l.ListItems.Add
    i.Text = "col1"
    i.SubItems(1) = "col2"
    i.SubItems(2) = "col3"
    next j
    Dim x as Excel.Application
    set x = CreateObject("Excel.Application")
    Dim w as Excel.Workbook
    set w = x.Workbooks.Add
    x.Visible = true
    Dim row
    Dim col
    Dim strRange as string
    for row = 1 to l.ListItems.Count
    strRange = "A" & row
    w.ActiveSheet.Range(strRange).Value = l.ListItems(row).Text
    for col = 1 to l.ColumnHeaders.Count - 1
    strRange = Chr(Asc("A") + col) & row
    Debug.print strRange
    w.ActiveSheet.Range(strRange).Value = l.ListItems(row).SubItems(col)
    next
    next
    End Sub






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured