Results 1 to 5 of 5

Thread: Excel Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177

    Unhappy Excel Question

    Hello guys! I don't have my books with me right now and I'm trying to create an application that:

    1) Opens an Existing Excel Worksheet
    2) Read in the Values from the Active Worksheet
    3) Write data back to the Active Worksheet

    Does anyone have some basic code that will do this? I've seen a lot of the code posted here on this site but it's a little too in-depth for what I'm trying to do. Thanks for the help!
    212 will lead you to the truth

  2. #2
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Easy thing to do:

    1st Step: Go to Project --> References and reference the Microsoft Excel Object Library

    2nd Step:

    'Excel Application Variable
    Dim xlApp as Excel.Application
    Dim strText as String

    'Opens an instance of Excel
    set xlApp = createobject(Excel.Application)

    'Open the document
    xlApp.Workbooks.Open("MyFile.XLS")

    'Activate the first sheet
    xlApp.Sheets(1).Activate

    'Read/Write to a cell. 1,1 is A1, 2,1 would be A2, etc..
    strText = xlApp.Workbooks.Application.Cells(1,1)
    strText = strText & " - I changed this text"
    xlApp.Workbooks.Application.Cells(2,1) = strText

    xlApp.Workbooks.Item(1).SaveAs "MyNewFile.XLS"

    xlApp.Workbooks.Close
    xlApp.Quit

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    Thanks I'll try this!
    212 will lead you to the truth

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    I'm getting an error (ActiveX component can't create object) on the line:
    Set xlApp = CreateObject(Excel.Application)
    212 will lead you to the truth

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    Never mind I fixed it. I forgat the quotes.
    212 will lead you to the truth

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