I'm trying to understand something.
I've found the following code on the web. Have cleaned it up to show the relevant parts.
Why do we Create Excel.Application before opening the excel file with data.
It's like opening a box and placing a smaller box inside it? Is the first step (Creating the Excel.Application) necessary? This part just gives me a frame. I'm doing this from Access which is why I've placed it in the Access forum.
Private Sub cmdLoad_Click() Dim excel_app As Object Dim excel_sheet As Object Dim conn As ADODB.Connection ' Create the Excel application ----------WHY DO WE DO THIS? Set excel_app = CreateObject("Excel.Application") ' Uncomment this line to make Excel visible. excel_app.Visible = True ' Open the Excel spreadsheet.---------------OPENING THE EXCEL FILE WITH DATA excel_app.Workbooks.Open FileName:=txtExcelFile.Text
Thanks so much.
Danny2000
This kind of goes into the concept of object oriented programming. When you want to use an object, you have to first create an instance of that object.
It may help to think about it as if we were not programming, but rather doing it manually. If you want to open an Excel file, Excel must first be open. Even when you open the file from Windows Explorer, first Excel starts, then Excel loads the file.
You code above does the same thing. First, it starts an instance of Excel, then it opens a file.
Is your code running too slowly?
Does your workbook or database have a bunch of duplicate pieces of data?
Have a look at this article to learn the best ways to set up your projects.
It will save both time and effort in the long run!
Dave
Thanks very much. Now that I look at it I believe you are 100% correct. Thanks Again.
Danny2000
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks