Outlookに接続するスクリプトを作成して、既に作成されたフォルダに移動します。フォルダが存在しない場合はOutlookの特定のフォルダを検索し、電子メールをそのフォルダに移動するためのルールを作成するVBScriptを作成します。
'--> Create some constants
Const olRuleReceive = 0
'--> Create some variables
Dim olApp, olSession, olRuleDirectory, newRule, ruleConditions, ruleAction, folderDirectory, newFolder, moveFolder, index, ruleActiona
Dim folderexists
'--> Connect to Outlook
Set olApp = CreateObject("Outlook.Application")
Set olSession = olApp.GetNamespace("MAPI")
olSession.Logon olApp.DefaultProfileName
' --> Get the rules/folder collection
Set folderDirectory = olSession.GetDefaultFolder(6)
Set moveFolder = folderDirectory.Parent
For i = 1 To moveFolder.Folders.Count
If moveFolder.Folders.item(i).Name = "One" Then
index = i
Exit For
End If
Next
' set moveFolder = moveFolder.Folders.item(index)
Set olRuleDirectory = olSession.DefaultStore.GetRules()
'--> Create a new receive rule
Set newRule = olRuleDirectory.Create("Test", olRuleReceive)
'--> Set the rule's condition to look for a specific word in the subject
Set ruleConditions = newRule.Conditions.Body
With ruleConditions
.Text = Array("test")
.Enabled = True
End With
' --> Set the rule's action to move to folder
Set ruleAction = newRule.Actions.MoveToFolder
With ruleAction
.Enabled = True
.Folder = moveFolder.Folders(index) ' this is the part that needs work, a variable needs to be delcared earlier and set to a folder directory.
End With
'--> Save the rule
olRuleDirectory.Save False
'--> Disconnect from Outlook
olSession.Logoff
Set ruleConditions = Nothing
Set ruleAction = Nothing
Set newRule = Nothing
Set olRuleDirectory = Nothing
Set olSession = Nothing
Set olApp = Nothing
'--> Terminate the script
WScript.Quit
したがって、どのラインで正確にエラーがスローされますか? –
行47 - '.Folder = moveFolder.Folders(index)' –