Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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 55

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

571 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