Results 1 to 2 of 2

Thread: visual basic in excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    1

    Question

    I'm currently using Excel as part of a school project, I need to know how to get info from a text box in userform, to a specific cell in a workbook. Can anyone please help me, since quite a bit of the project is based on this feature of people entering data into user frorm created through the visual basic part, and it moving to the spreadsheet.

    Thankyou

  2. #2
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Hi.
    In references, put a reference to Microsoft Excel 9.0 Library.

    Then code

    Dim xlsWorkBook As Excel.Workbook
    Dim xlsWorkSheet As Excel.Worksheet

    Command1_Click()
    Set xlsWorkBook = GetObject("C:\MyDocuments\whatever.xls")
    Set xlsWorkSheet = xlsWorkBook.Worksheets("Sheet1")


    xlsWorkSheet.Cells(1, 1).value = Text1.Text 'This represent cell A1.
    xlsWorkSheet.Cells(2, 1).value = Text2.Text 'This represent cell A2
    xlsWorkSheet.Cells(1, 2).value = Text3.Text 'This represent cell B2


    'when you're finished

    xlsWorkBook.Close
    End Sub

    I think that's about it

    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

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