Storing data from vb form to excel cell

Posted on 2003-03-02
Medium Priority
Last Modified: 2010-05-01
I want to input data in  visual basic userform textboxes. These data wil be stored in excel files ( in user defined cell). Those data will be processed for different job.
If anybody can suggest me that will be great for me.

Thanks in advance.
Question by:kazal
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8054628
to get you started:
1. Add a reference to Excel in Project's References
2. Use the CreateObject function to create an Excel worksheet object
3. Reference this worksheet object and use its methods and properties to modify the worksheets cells (like in VBA in Excel)

There are plenty of sample code around. try www.planetsourcecode.com
LVL 53

Accepted Solution

Ryan Chong earned 60 total points
ID: 8054761
Here is an example that export content of Listview to an Excel file, try customize it so that it export the textboxes value to Excel.


Private Sub ExportFromListViewToExcel(ByVal TargetFile As String, ByVal SheetName As String, ByVal myListView As MSComctlLib.ListView)
    Dim iExcel As New Excel.Application
    Dim iExcelWB As Excel.Workbook
    Dim iExcelWS As Excel.Worksheet
    iExcel.Visible = True
    If dir$(TargetFile) <> "" Then
        iExcel.Workbooks.Open TargetFile
    End If
    i = iExcel.Workbooks.Count
    Set iExcelWB = iExcel.Workbooks(i)
    j = iExcel.Workbooks(i).Worksheets.Count
    Set iExcelWS = iExcelWB.Worksheets(j)
    'Set iExcelWS = iExcelWB.ActiveSheet
    iExcelWS.Name = SheetName
    iExcelWS.Columns(1).ColumnWidth = 20
    iExcelWS.Columns(2).ColumnWidth = 10
    iExcelWS.Columns(3).ColumnWidth = 10
    iExcelWS.Columns(4).ColumnWidth = 50
    'iExcelWS.Range("A1", "G100").EntireColumn.AutoFit
    iExcelWS.Range("A1", "D1").Font.Bold = True
    iExcelWS.Range("A1", "G100").EntireColumn.WrapText = True
    For j = 1 To myListView.ColumnHeaders.Count
        iExcelWS.Cells(1, j).Value = myListView.ColumnHeaders(j).Text
    Next j
    For j = 1 To myListView.ListItems.Count
        iExcelWS.Cells(j + 1, 1).Value = myListView.ListItems(j).Text
        For h = 1 To myListView.ColumnHeaders.Count - 1
            iExcelWS.Cells(j + 1, h + 1).Value = myListView.ListItems(j).SubItems(h)
        Next h
    Next j
    If Check1.Value = 1 Then
        Set iExcelWS = Nothing
        Set iExcelWB = Nothing
        Set iExcel = Nothing
    End If
End Sub

Hope this helps

Expert Comment

ID: 8940410
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
LVL 49

Expert Comment

ID: 9012088
Moderator, my recommended disposition is:

    Accept ryancys's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question