Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2014-12-21
Medium Priority
Last Modified: 2015-02-09
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
Question by:mainrotor
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
LVL 85
ID: 40512594
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?
LVL 31

Expert Comment

ID: 40512600
Will dealing with the file as a linked table be of any good?
This way you update in excel, and manage in access.

Expert Comment

ID: 40512748
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 40512969
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.

Expert Comment

ID: 40513240
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...
LVL 31

Expert Comment

ID: 40513329
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
LVL 39

Expert Comment

ID: 40513370
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.

Author Comment

ID: 40520172
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,
LVL 85

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 40520322
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.

Author Comment

ID: 40547556
I think you are correct.  I will probably use temporary tables for this.  Will post my results later.

LVL 49

Expert Comment

by:Martin Liss
ID: 40597933
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

636 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