|
-
Feb 18th, 2002, 10:28 AM
#1
Thread Starter
Addicted Member
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
-
Feb 18th, 2002, 10:58 AM
#2
Hyperactive Member
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
-
Feb 18th, 2002, 11:05 AM
#3
Thread Starter
Addicted Member
212 will lead you to the truth
-
Feb 18th, 2002, 11:12 AM
#4
Thread Starter
Addicted Member
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
-
Feb 18th, 2002, 11:14 AM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|