Hallo Matthias,
vielen, vielen Dank.
Das sieht echt klasse aus.
Genau wie du vermutest hast habe ich die Stringsuche als Funktion in ein bestehendes Sub eingefügt.
Wenn ich diesen ausführe soll er mir jetzt bevor ich weiter am Code arbeite sagen treffer oder kein treffer per MsgBox
Was macht der Code :
1) Er liest den Subject einer Email und speichert diesen als String
2) Er sucht mit deiner Funktion in dem Strin nach Treffer
Scheinbar übergibt er aber den String nicht korrekt da er immer sagt "kein treffer"
Hast du hierzu eine Idee woran es scheitert ?
Beste Grüße Henry
Public Sub Subject()
Dim obj As Object
Dim Sel As Outlook.Selection
Dim DoSave As Boolean
Dim NewSubject As String
If TypeOf Application.ActiveWindow Is Outlook.Inspector Then
Set obj = Application.ActiveInspector.CurrentItem
Else
Set Sel = Application.ActiveExplorer.Selection
If Sel.Count Then
Set obj = Sel(1)
DoSave = True
End If
End If
If Not obj Is Nothing Then
stringsearch
End If
End Sub
Function stringsearch()
Dim stext As String 'the string in which you search
Dim result As Variant 'the result of seach
Dim member As Variant 'the members of the search if it are more than one
Dim found As Boolean ' if you found a string
Dim Regex As Object
found = False
'stext = obj.Subject 'here you must adapt either the string or where he is from, if you use the code as a function I suppose stext comes as argument, then delete this row
Set Regex = CreateObject("Vbscript.Regexp")
With Regex
.Pattern = "\d[a-zA-Z]{5}\d{4}" 'this stand for digit - 5 letters (small or capital) and 4 digits
.IgnoreCase = False
.Global = True ' if you found a result it will look for further hits
If .Test(stext) Then found = True ' you found a seached string
Set result = .Execute(stext) 'starts the search
End With
Set Regex = Nothing
If found = True Then ' you found a string
For Each member In result
'place here all you want to do with the found string f.e. save
MsgBox "you got a hit!" & stext
Next member
Else ' you found nothing and can send a message or do anything else
MsgBox "IDIOT!"
End If
Set result = Nothing
End Function
|