vba用户定义类型vb变量未定义义

查看: 3678|回复: 1
所有ADODB.Connection 时,都会出现用户定义类型未定义如何解决
我在所有涉及到& &所有ADODB.Connection 时,都会出现用户定义类型未定义如何解决,我已经在引用中加了Microsoft visual basic for application 5.3还是不行
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
希望能帮忙解答下,谢谢。
本帖最后由 dongqing1998 于
22:05 编辑
添加下面的引用。
.jpg (56.63 KB, 下载次数: 13)
20:56 上传
如果不想前期绑定,也可以用下面的方法进行后期绑定:
set cnn = createobject(&adodb.connection&)
|||Excel精英培训
Powered byvba中EXCEL&调用WORD&时出现用户类型未定义”解决办法
EXCEL的一个VBA程序调用WORD文档,发现“Dim wdApp As
Word.Application”出现编译错误,出错原因是“用户定义类型未定义”,后来发现其解决办法,是因为VBA
引用的问题。:
在excel VBA的环境中,引用word的类库。
1、工具、引用
2、勾选“Micrsoft Word 11.0 Object Library”,单击确定。
在Excel2003下测试正常。
如果使用的EXCEL 2007 ,则勾选Micrsoft Word 12.0 Object Library
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。查看: 6436|回复: 5
行时提示“用户定义类型未定义”?
阅读权限20
在线时间 小时
在论坛上看到用Excel生成Word文档的例子,想修改一下自己用,
可总是运行时提示“用户定义类型未定义”。
但在原例子中不出现,不知怎么回事?
我对VBA不大了解,请赐教。
代码如下:
Private Sub CommandButton输出通知到Word文件_Click()
& &Dim Word对象 As New Word.Application, 当前路径, 导出文件名, 导出路径文件名, i, j
& &Dim Str1, Str2
& &运行到“Word对象 As New Word.Application,”时,提示“用户定义类型未定义”
& &不知怎么办?
[ 本帖最后由 lhteee 于
16:38 编辑 ]
阅读权限20
在线时间 小时
& & & & & & & &
有谁知道?
是不是需要对Word进行设置?
阅读权限50
在线时间 小时
回复 1楼 lhteee 的帖子
添加引用:Microsoft Scripting Runtime
C:\WINDOWS\system32\scrrun.dll
阅读权限20
在线时间 小时
自己解决了!
为了能够在VB中应用Word对象组建库,需要在工程中添加对该对象的引用,添加应用的方法是在VBA编辑器中执行“工具”菜单的“引用”命令,然后在“引用”对话框中选择“Microsoft& &Word& &11.0& &Obkect& &libary”&&即可。
阅读权限20
在线时间 小时
& & & & & & & &
原来是这样。我也遇到这问题,有你的贴就解决了,谢谢。
阅读权限20
在线时间 小时
Option Explicit
Dim arrFiles()
Dim cntFiles%
Sub Main()
&&Dim i%, StartFolder$, SavePath$
&&Dim fso As New FileSystemObject, fd As Folder
&&ReDim arrFiles(1 To 1000)
&&cntFiles = 0
&&StartFolder = &D:\Word&& && & '原文件目录
&&SavePath = &D:\Word2&& && && & '改名后的文件目录
&&Set fd = fso.GetFolder(StartFolder)
&&SearchFiles fd
&&ReDim Preserve arrFiles(1 To cntFiles)
&&For i = 1 To cntFiles
& & RenameDocument arrFiles(i), SavePath, i
Sub SearchFiles(ByVal fd As Folder)
&&Dim fl As File
&&Dim sfd As Folder
&&For Each fl In fd.Files
& & If LCase(Right(fl.Path, 4)) = &.doc& Then
& && &&&cntFiles = cntFiles + 1
& && &&&If cntFiles &= UBound(arrFiles) Then ReDim Preserve arrFiles(1 To cntFiles + 1000)
& && &&&arrFiles(cntFiles) = fl.Path
& & End If
&&If fd.SubFolders.Count = 0 Then Exit Sub
&&For Each sfd In fd.SubFolders
& & SearchFiles sfd
Sub RenameDocument(ByVal wordFileName, ByVal wordFilePath, ByVal num)
On Error Resume Next
& & Dim myTitle$, myFileName$
& & Dim mydoc As Document, myRange As Range
& & Set mydoc = Word.Documents.Add
& & mydoc.Activate
& & Selection.InsertFile fileName:=wordFileName, Range:=&&, ConfirmConversions:= _
& && &&&False, Link:=False, Attachment:=False
& & ActiveWindow.View.Type = wdPageView
& & Set myRange = mydoc.Paragraphs.First.Range
& & myRange.SetRange myRange.Start, myRange.End - 1
& & myTitle = Trim(myRange.Text)
& & If (myTitle = &&) Or (Len(myTitle) & 50) Then
& && &&&Debug.Print &ERR:--------------------------------------------& + wordFileName
& && &&&Shell &cmd.exe /c echo & & &ERR:--------------------------------------------& & wordFileName & &&&D:\Word.log&
& && &&&mydoc.Close SaveChanges:=wdDoNotSaveChanges
& && &&&SendKeys (&{ESC}&)
& && &&&Exit Sub
& & End If
& & myFileName = wordFilePath + &\& + myTitle + &.doc&
& & mydoc.SaveAs myFileName
& & mydoc.Close SaveChanges:=wdDoNotSaveChanges
& & Debug.Print num & &:& & wordFileName & &=& & myFileName
& & Shell &cmd.exe /c echo & & num & &:& & wordFileName & &=& & myFileName & &&&D:\Word.log&
我的这个,也说用户定义类型末定义,啥情况? 程序是网下的,word
玩命加载中,请稍候
玩命加载中,请稍候
Powered by
本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任! & & 本站特聘法律顾问:徐怀玉律师 李志群律师

我要回帖

更多关于 vb变量未定义 的文章

 

随机推荐