什么是“未定义编译错误用户定义类型"? [英] What is "Compile error User-defined type not defined"?

查看:218
本文介绍了什么是“未定义编译错误用户定义类型"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将工作表从Excel 2007导出到Windows 7上的Access 2007,包括创建新表.我已经在Excel中尝试了以下VBA,但状态为未定义编译错误用户定义类型",然后突出显示Access对象的第一个变量声明.我引用了Microsoft ActiveX数据对象6.1库.

I am attempting to export a worksheet from Excel 2007 to Access 2007 on Windows 7 including creating a new table. I have tried the following VBA in Excel but it states "Compile Error User-defined types not defined" and then highlights the first variable declaration for the Access object. I have the Microsoft ActiveX Data Objects 6.1 Library referenced.

怎么了?

Dim acc As New Access.Application
Dim ws As Worksheet
Dim ThisWorkbook As Workbook
Dim a As Long
Dim b As Long

Set ThisWorkbook = ActiveWorkbook
Set ws = ThisWorkbook.Sheets("CompleteNoFormat3")
a = ws.UsedRange.Rows.Count
b = ws.UsedRange.Columns.Count

acc.OpenCurrentDatabase "CustDB.mdb"
  acc.DoCmd.TransferSpreadsheet _
   TransferType:=acImport, _
   SpreadSheetType:=acSpreadsheetTypeExcel12Xml, _
   TableName:="CustExportTable", _
   Filename:=Application.ActiveWorkbook.FullName, _
   HasFieldNames:=True, _
   Range:="BAPCompletNoFormat$A1:" & a & B 
acc.CloseCurrentDatabase
acc.Quit
Set acc = Nothing

推荐答案

考虑使用后期绑定,如果将应用程序分发给可能安装了不同库版本类型的多个用户,则有时甚至建议使用.

Consider using late binding which is even sometimes recommended if distributing applications to multiple users who may have different library version types installed.

后期绑定避免了在CPU搜索适当类型和不支持新建"关键字:

Late binding avoids needs to specifically choose references as CPU searches for appropriate type and for applications that do not support the "New" keyword:

Dim acc As Object

Set acc = CreateObject("Access.Application")

这篇关于什么是“未定义编译错误用户定义类型"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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