800A0401 - Expected End of Statement

可紊 提交于 2019-11-27 05:04:29

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.

Instead, you want:

Dim myNameSpace
Dim myFolder
Dim myNewFolder

Additionally, you seem to have just copied some VBA from Outlook and tried to run it as VBS.

VBscript does not know how to interpret Application.GetNameSpace("MAPI").

You will need to also create an Outlook Application.

dim myOutlook
set myOUtlook = CreateObject("Outlook.Application")

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!