语句的预期结尾"错误代码800A0401
"Expected End of Statement" error code 800A0401
Option Explicit
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myNewFolder As Outlook.Folder
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myNewFolder = myFolder.Folders.Add("Postini")
Wscript.Echo "Folder created"
Wscript.Quit
以前从未创建过.vbs脚本.
Never created a .vbs script before.
Windows 7 64位和Outlook2010.以本地管理员身份运行.
Windows 7 64-bit and Outlook 2010. Running as local administrator.
推荐答案
此错误是因为您不能将变量变暗,尤其是在VBS中.更明确地说,使用"Dim"语句时无需在VBScript中定义变量类型,因为VBScript中的所有变量自动都是Variant类型.如果您尝试将变量变暗为任何东西,它将引发错误.
This error is because you cannot dim variables as something in particular in VBS. Said more explicitly the "Dim" statement is used without defining the variable type in VBScript because all variables in VBScript are automatically of type Variant. If you attempt to Dim a variable as anything, it will throw an error.
相反,您想要:
Dim myNameSpace
Dim myFolder
Dim myNewFolder
此外,您似乎刚刚从Outlook复制了一些VBA,并尝试将其作为VBS运行.
Additionally, you seem to have just copied some VBA from Outlook and tried to run it as VBS.
VBscript不知道如何解释Application.GetNameSpace("MAPI")
.
VBscript does not know how to interpret Application.GetNameSpace("MAPI")
.
您还需要创建一个Outlook应用程序.
You will need to also create an Outlook Application.
dim myOutlook
set myOUtlook = CreateObject("Outlook.Application")
此外,由于无法在VBS中提供引用,因此必须对任何对象使用后期绑定(这就是我使用CreateObject的原因.)因此,代码重写如下:
Also, since you cannot provide references in VBS, you have to use late binding for any objects (which is why I used CreateObject.) So re-written your code is as follows:
Option Explicit
Dim myOutlook
Dim myNameSpace
Dim myFolder
Dim myNewFolder
set myOUtlook = CreateObject("Outlook.Application")
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(6) '6 is the value of olFolderInbox
Set myNewFolder = myFolder.Folders.Add("Postini")
Wscript.Echo "Folder created"
Wscript.Quit
这篇关于在Outlook中创建一个文件夹:错误800A0401-预期的语句结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!