VBA Access 编译错误变量未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18363820/
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
VBA Access Compile Error variable not defined
提问by ELS31987
I have this script that I want to use to move folders for archive this is my code :
我有这个脚本,我想用它来移动文件夹以进行存档,这是我的代码:
Public Function modbalsmovearhive()
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.MoveFile "H:\Credit_Bals*.xls", "H:\Bals_Archive\"
End Function
Now when I go to run it I get the Compile Error variable not defined. Can someone assist me with the best way to resolve this error.
现在,当我去运行它时,我得到了未定义的编译错误变量。有人可以帮助我解决此错误的最佳方法。
采纳答案by Graham Anderson
I think you may have forgotten to dimension the object, I'm guessing using:
我想您可能忘记了标注对象的尺寸,我猜想使用:
Dim FSO As FileSystemObject
Also make sure that you have the reference checked for Microsoft Scripting Runtime.
还要确保您检查了 Microsoft Scripting Runtime 的参考。
回答by jlaverde
I just tested the code and it works. Make sure Option Explicit is not On, and also make sure have included all the libraries you are using in your code.
我刚刚测试了代码,它可以工作。确保 Option Explicit 未打开,并确保已在代码中包含您正在使用的所有库。
EDIT: It is NOT good practice to have Option Explicit Off, so if you do want to keep it on, make sure all your variables are declared and your libraries included.
编辑:关闭 Option Explicit Off 不是一个好习惯,所以如果你想保持它,请确保你的所有变量都被声明并包含你的库。
回答by Nikhil Arora
Also note that after putting define variable option OFF, existing module wouldn't change, that is, existing module will continue to have Option Explicit. In that case you need to copy code to a new module.
另请注意,将定义变量选项设置为 OFF 后,现有模块不会改变,即现有模块将继续具有 Option Explicit。在这种情况下,您需要将代码复制到新模块。