mainrotor
asked on
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.
How can I do this? Thanks in advance
mrotor
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_cmdOLEAuto_Click:
Exit Sub
Error_cmdOLEAuto_Click:
MsgBox CStr(Err) & " " & Err.Description
Resume Exit_cmdOLEAuto_Click
End Sub
How can I do this? Thanks in advance
mrotor
Will dealing with the file as a linked table be of any good?
This way you update in excel, and manage in access.
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
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
ASKER
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.
mrotor
Can you please provide a sample of how I would do what I need to do, using a linked Excel workbook.
Thank you.
mrotor
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...
- 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
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.
ASKER
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)
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)
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,
mrotor
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)
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)
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,
mrotor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Scott,
I think you are correct. I will probably use temporary tables for this. Will post my results later.
mrotor
I think you are correct. I will probably use temporary tables for this. Will post my results later.
mrotor
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Why not just link the Excel workbook to Access, and grab the data that way?