简体   繁体   中英

Updating .accdb using Excel data from ACCESS VBA

I've been looking for a method of updating an Access database with data stored in an Excel file, but I can only find methods from Excel VBA and not through Access itself which is not what I want. This would be to dynamically update an Access table with data that is regularly updated in an Excel file. I have the table in Access set up with an autonumber as a primary key. I just need a code to do this on command (like a 'refresh button').

I've found this link helpful in doing it through Excel ( Updating Access Database from Excel Worksheet Data ). I would like a way to do it solely in Access (without opening Excel; just referencing the data in the worksheet(s)). Is this possible?

You can't do it via an sql statement that I know of, but you can could create a button which when clicked opens the workbook/sheet and then retrieves data from it into your database - something like:

dim XL as object
dim WB as object
dim WS as object

Set XL = CreateObject("Excel.Application")
XL.Visible = False
XL.DisplayAlerts = False
Set WB = XL.workbooks.open(pathname)
Set WS = WB.Worksheets("Sheet1")

Then retrieve data into access using the cell references of that data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM