如何在 Access VBA 中引用 Excel 对象? [英] How to refer to Excel objects in Access VBA?
问题描述
为了能够使用 Access 2007 VBA 脚本中的 Excel 对象和常量,我必须做出哪些声明?
What declarations I have to make in order to be able to use Excel objects and constants from my Access 2007 VBA script?
Dim wb As Workbook
或
Set objExcelApp = New Excel.Application
或
.Borders(xlEdgeBottom)
推荐答案
首先您需要设置对 Microsoft Excel 对象库的引用(菜单:工具->引用),然后您可以访问所有 Excel 对象.
First you need to set a reference (Menu: Tools->References) to the Microsoft Excel Object Library then you can access all Excel Objects.
添加引用后,您可以完全访问所有 Excel 对象.您需要在所有内容前面添加Excel,例如:
After you added the Reference you have full access to all Excel Objects. You need to add Excel in front of everything for example:
Dim xlApp as Excel.Application
假设您在表单中添加了一个 Excel 工作簿对象并将其命名为 xLObject.
Let's say you added an Excel Workbook Object in your Form and named it xLObject.
这是访问此对象的工作表并更改范围的方法
Here is how you Access a Sheet of this Object and change a Range
Dim sheet As Excel.Worksheet
Set sheet = xlObject.Object.Sheets(1)
sheet.Range("A1") = "Hello World"
在 Access 中使用 Excel 的另一种方法是通过 Access 模块启动 Excel(shahkalpesh 在他的回答中描述的方式)
Another way to use Excel in Access is to start Excel through a Access Module (the way shahkalpesh described it in his answer)
这篇关于如何在 Access VBA 中引用 Excel 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!