Solved

open a existing excel workbook

Posted on 2000-03-01
3
196 Views
Last Modified: 2012-05-04
I am trying to open a existing excel workbook. Inside of it contains 7 sheets and I require to change input the information into cells. Can anyone tell me how to do so????I have use "set wb = getobject("c:\sale.xls") " to open this workbook. It seems like I had open the workbook. However, what ever information I had try to put into the worksheet is not sucessful. Can anyone take me through this???? Thanks
0
Comment
Question by:c4mar
3 Comments
 

Expert Comment

by:woodsrr
Comment Utility
Try this:

I have a form with just 1 command buttons. The button opens a excel document, prints the value from cell 1,1 and then changes the value of cell 1,1.  
When you are done with your excel object call the xlApp.Quit method and then set your xlApp object to nothing to free up the resource.

Dim xlApp As Object

Private Sub Command1_Click()
    Set xlApp = CreateObject("excel.application")
    xlApp.Visible = True
    xlApp.workbooks.Open "C:\My Documents\CarLoc.xls"
    Print xlApp.Cells(1, 1) ' Printing the value of cell 1,1
    xlApp.Cells(1, 1) = "New Text" ' Changing the value of cell 1,1
End Sub

0
 
LVL 1

Expert Comment

by:georgeman
Comment Utility
One more thing.
If you need update cell in particulary sheet, you need activate this sheet before or use sheet name directly in Excel object:

xlApp.Worksheets("MySheet").Activate
xlApp.Cells(1, 1) = "New Text" ' Changing the value of cell 1,1

or

xlApp.Worksheets("MySheet").xlApp.Cells(1, 1) = "New Text" ' Changing the value of cell 1,1
0
 

Accepted Solution

by:
dalbello earned 30 total points
Comment Utility
Try this
-------------------------------------------------
Sub test()
' declare the objects
Dim wb As Workbook
Dim s1 As Worksheet
Dim s2 As Worksheet
Dim s3 As Worksheet
' ... etc
' ... etc
' Set the objects
Set wb = GetObject("c:\sale.xls")
Set s1 = wb.Sheets("NameOfSheet1")
Set s2 = wb.Sheets("NameOfSheet2")
Set s3 = wb.Sheets("NameOfSheet3")
' ... etc
' ... etc
' Write text in cells A1 of s1, s2 and s3
s1.Cells(1, 1).Value = "TEST TEXT"
s2.Cells(1, 1).Value = "TEST TEXT"
s3.Cells(1, 1).Value = "TEST TEXT"
' ... etc
' ... etc
End Sub
----------------------------------------------------
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now