用户类型未定义工作表 VBA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15466331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:05:13  来源:igfitidea点击:

user-type not defined Worksheet VBA

excelvbaexcel-vbams-wordword-vba

提问by jonypz

I have tried to add references to my project so I can get this error solved but I haven't been successful.

我试图添加对我的项目的引用,这样我就可以解决这个错误,但我没有成功。

Could anyone please tell me which libraries should I add?

谁能告诉我应该添加哪些库?

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add

 'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("C:\")
ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & "are:"

 'Loop through the Files collection
For Each objFile In objFolder.Files
    ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
    MyFile = objFile.Name
      NewName = getNewFileName()

回答by dee

If you are working within Word IDEthen go to Tools -> Referencesand browse for Microsoft Excel [version number] Object Library:

如果您在 Word IDE中工作则转到工具 -> 参考并浏览Microsoft Excel [版本号] 对象库

enter image description here

在此处输入图片说明

回答by Olle Sj?gren

You have tagged the question word-vba, but you are using the Worksheetsreference, which is part of Excel.

您已将问题标记为word-vba,但您正在使用Worksheets参考,它是 Excel 的一部分。

If you really are using the Worksheetsreference in Word you would get the User-defined type not defined-error.

如果你真的Worksheets在 Word中使用引用,你会得到User-defined type not defined-error。

If not, something else is missing and you need to tell us more. What line does the error highlight etc.

如果没有,则缺少其他内容,您需要告诉我们更多信息。错误突出显示了哪一行等。