如何在Access VBA中引用Excel对象? [英] How to refer to Excel objects in Access VBA?

查看:379
本文介绍了如何在Access VBA中引用Excel对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了能够使用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的另一种方法是通过访问模块启动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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆