I need assistance reading values in an embedded Excel File in Access

Hi Experts,
I found the code below on line, which allows me to open an Excel file as an Embedded OLE Object in ACCESS.  
Now that I load the Excel file , I want to:
1. be able to manipulate the Excel file from within EXCEL
2. read/loop through the updated data in the Embedded object, and Save the data to a table in my ACCESS database I click on a button.

Private Sub cmdOLEAuto_Click()
   On Error GoTo Error_cmdOLEAuto_Click
   With Me![OLEExcelSheet]
      .Enabled = True
      .Locked = False
      ' Specify what kind of object can appear in the field.
      .OLETypeAllowed = acOLEEmbedded
      ' Class statement for Word document.
      .Class = "Excel.Sheet"
      ' Specify the file to be embedded.
      ' Type the correct path name.
      .SourceDoc = "c:\OLETEST.xls"
      ' Create the embedded object.
      .Action = acOLECreateEmbed
   End With
   Exit Sub
   MsgBox CStr(Err) & " " & Err.Description
   Resume Exit_cmdOLEAuto_Click
End Sub

Open in new window

How can I do this?  Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
be able to manipulate the Excel file from within EXCEL
Do you mean you want to do that while someone has it open in Access? If so, then I don't believe you can do that.

Why not just link the Excel workbook to Access, and grab the data that way?
Will dealing with the file as a linked table be of any good?
This way you update in excel, and manage in access.
Is there a good reason to embed the excel file?

Normally the manipulation part is standard, just double click on the OLE Object. You are however restricted by the control size which is a pain.
Or better, right click the OLE then WorksheetObject Open (not Edit!)

To read the data from the embedded excel object you need to open it:
in your button code something like this:
Edit: corrected typo in code
Private Sub Command2_Click()
    Me![OLEExcelSheet].Verb = acOLEVerbOpen
    Me![OLEExcelSheet].Action = acOLEActivate
    Set Xl = GetObject(, "Excel.Application")
    Debug.Print Xl.Cells(1, 1).Value
End Sub

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mainrotorAuthor Commented:
Scott and hnasr,
Can you please provide a sample of how I would do what I need to do, using a linked Excel workbook.

Thank you.
You mean there is no need to embed:
- You are dealing with a single excel file
- When moving around the access file in the file system, having to redefine the link is not a problem
Then in the Access DB, go to the ribbon tab External Data, Click Excel, and follow the wizard...
Here is a sample.
Edit in excel, and mange in access. You may query, create form, report, and create new tables.
The example was created in D:\linked
I am confused by your process.  Why are you storing the Excel object in the Access database? Or, why are you manipulating a stored object?  Access isn't a particularly good file manager.  I would use Access to store templates that I use to create workbooks and then populate but once the workbook is populated, I would put it into a directory somewhere for the user to control.  If Access manages the data, you are essentially storing it twice.  Once in a table and again in the spreadsheet.
mainrotorAuthor Commented:
Hi Pat and other Experts,
I am not storing the Excel object in my Access database.

Here is step-by-step that will explain why I need the Linked or Embedded Excel in my Access 2013 application.
My application will be used to schedule employees for a given job.  The application will use the following two tables:  tblEmployeeAvailability, and tblScheduledEmployees.
Step 1: Select a job,  to schedule, from the Job combo box  (this will display the job's start and end dates)
Step 2: When the Job combo box's On Change event executes:
•      The employees available to work the job will be selected from table tblEmployeeAvailability
•      The available employees will be loaded into an embedded or linked Excel spreadsheet (see image below)
Initial Excel workbook
Step 3:  I want to then, manipulate the Excel workbook to mark the dates I want to schedule the employees to work  (see image below)
Marked Excel workbook
Step 4: Click the Schedule Selected Employees button.  This will read the manipulated Excel workbook and save the data into the tblScheduledEmployees table.
NOTE: the Excel workbook will not be saved in the database.

If there is a better, much easier way of doing this, please let me know.  
I don't really want to do it this way, but i don't know how to accomplish what i need to do by just using Access controls.

Is what I am trying to do possible?  If so, how?

Thanks in advance,
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
IMO it would be far simpler to use temporary tables to handle this.

In Step 2, after determining which employees are available for work, you would insert them into a temporary table. For example:

With CurrentProject.Connection
  .Execute "DELETE * FROM TempTable"
  .Execute "INSERT INTO TempTable(Employee, Col1, Col2, Col3) SELECT Employee, '', '', '' FROM EmployeeAvailibilty"
End With

Now create a Subform that is based on TempTable, and show that. Allow the user to enter an "x" into the rows where you want the Employee to be scheduled. You might consider using a Continuous form, since you could then use the Header of that form to include Labels to show the names of those columns.

When finished, use the data in TempTable to write back to your tblScheduledEmployees table.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mainrotorAuthor Commented:
I think you are correct.  I will probably use temporary tables for this.  Will post my results later.

Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.