derwowusste
Goto Top

Syntaxfrage zu Skript zur Outlookregelerstellung

Moin.

Habe folgendes VB-Skript:
Const RULE_NAME = "Move SPAM to SPAM Folder"  
Const olRuleReceive = 0
Const olFolderInbox = 6
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA, oCurrentRule, blnFound
Set olkApp = CreateObject("Outlook.Application")  
Set olkSes = olkApp.GetNamespace("MAPI")  
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()

' Look to see if Rule Exists  
blnFound = False
For Each oCurrentRule In olkCol 
  If oCurrentRule.Name = RULE_NAME Then blnFound = True
Next

' If the Rule has not been found, add it  
If not blnFound Then
	Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
	Set olkCD1 = olkRul.Conditions.Subject
	With olkCD1
	    .Enabled = True
	    .Text = Array("***SPAM***")  
	End With
	Set olkMRA = olkRul.Actions.MoveToFolder
	With olkMRA
	    set .Folder = olkSes.GetDefaultFolder(olFolderInbox).Folders("SPAM")  
	    .Enabled = True
	End With
	olkCol.Save False
End If

olkSes.Logoff	
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

WScript.Quit
Dieses soll nun erweitert werden um eine Ausnahme, siehe Bild:
rule
Habt Ihr die Syntax parat für diese Ausnahme?

Content-ID: 377126

Url: https://administrator.de/forum/syntaxfrage-zu-skript-zur-outlookregelerstellung-377126.html

Ausgedruckt am: 02.04.2025 um 22:04 Uhr

Friemler
Lösung Friemler 15.06.2018 um 09:56:52 Uhr
Goto Top
Moin

Nur geraten:
Set olkEx1 = olkRul.Exceptions.Subject

With olkEx1
  .Enabled = True
  .Text    = Array("FW: ***SPAM***")  
End With


Siehe:

Rule Object
Rule.Exceptions Property
RuleConditions Object
RuleConditions.Subject Property
TextRuleCondition Object
TextRuleCondition.Text Property
emeriks
Lösung emeriks 15.06.2018 um 09:58:55 Uhr
Goto Top
DerWoWusste
DerWoWusste 15.06.2018 um 10:37:24 Uhr
Goto Top
@Friemler: Perfekt!
Const RULE_NAME = "test"  
Const olRuleReceive = 0
Const olFolderInbox = 6
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA, oCurrentRule, blnFound
Set olkApp = CreateObject("Outlook.Application")  
Set olkSes = olkApp.GetNamespace("MAPI")  
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()

' Look to see if Rule Exists  
blnFound = False
For Each oCurrentRule In olkCol 
  If oCurrentRule.Name = RULE_NAME Then blnFound = True
Next

' If the Rule has not been found, add it  
If not blnFound Then
	Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
	Set olkCD1 = olkRul.Conditions.Subject
	With olkCD1
	    .Enabled = True
	    .Text = Array("***SPAM***")  
	End With
	Set olkEx1 = olkRul.Exceptions.Subject

    With olkEx1
      .Enabled = True
      .Text    = Array("FW: ***SPAM***")  
    End With
	Set olkMRA = olkRul.Actions.MoveToFolder
	With olkMRA
	    set .Folder = olkSes.GetDefaultFolder(olFolderInbox).Folders("SPAM")  
	    .Enabled = True
	End With
	olkCol.Save False
End If

olkSes.Logoff	
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

WScript.Quit

Danke Euch beiden für die Links. Ja, das könnte man sich auch selber zusammenfriemeln, aber es hat sich ja ein Friemler gefunden face-wink

Vielen Dank!
DerWoWusste
DerWoWusste 15.06.2018 aktualisiert um 10:54:52 Uhr
Goto Top
Ich war zu voreilig.

Wie müsste der Code sein, damit die bisherige Regel mit dem selben Namen durch die neue ersetzt wird?
emeriks
emeriks 15.06.2018 aktualisiert um 11:04:07 Uhr
Goto Top
ungefähr so

set olkRul = nothing

' Look to see if Rule Exists  
For Each oCurrentRule In olkCol 
  If oCurrentRule.Name = RULE_NAME Then Set olkRul  = oCurrentRule 
Next

If olkRul  is Nothing then
  Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
end if

'kein Else !  

If not olkRul  is Nothing  Then
	Set olkCD1 = olkRul.Conditions.Subject
	With olkCD1
	    .Enabled = True
	    .Text = Array("***SPAM***")  
	End With
	Set olkEx1 = olkRul.Exceptions.Subject

    With olkEx1
      .Enabled = True
      .Text    = Array("FW: ***SPAM***")  
    End With
	Set olkMRA = olkRul.Actions.MoveToFolder
	With olkMRA
	    set .Folder = olkSes.GetDefaultFolder(olFolderInbox).Folders("SPAM")  
	    .Enabled = True
	End With
	olkCol.Save False
End If
DerWoWusste
DerWoWusste 15.06.2018 um 12:38:55 Uhr
Goto Top
Sehr schön, läuft. Nochmals Danke.
DerWoWusste
DerWoWusste 17.07.2018 aktualisiert um 10:29:36 Uhr
Goto Top
Hi emeriks.

Hast Du für mich vbs-Loser noch einen Tipp, wie die Syntax wäre, wenn man zwei Ausdrücke ausschließen wollte?
Also Ausnahme 1 wie gehabt: "FW: ***SPAM***"  
Und Ausnahme 2: "RE: ***SPAM***"  
?
emeriks
Lösung emeriks 17.07.2018 aktualisiert um 10:38:36 Uhr
Goto Top
Hi DWW,
Zeile 24 (meine Antwort: 15.06.2018, aktualisiert um 11:04 Uhr )
.Text    = Array("FW: ***SPAM***" , "RE: ***SPAM***")   

Das kannst Du beliebig erweitern.
DerWoWusste
DerWoWusste 17.07.2018 um 10:50:01 Uhr
Goto Top
Danke nochmals face-smile