VBscript - hot to find root of words with different endings?
Gesperrt
-
Wednesday, May 30, 2012 9:48 AM
For example:
If objParent.Items.Count >=10 and objParent.Name <> Test_Wor*
Does it make sense? So I need to find all Test_Word1, Test_Word2, etc. What is the best way to do it?
All Replies
-
Wednesday, May 30, 2012 10:21 AM
Sorry disregard this answer, I assumed PowerShell and completely missed VBscript in the title.
Depends, what kind of objects are you looking at. You also use the .Items.Count properties so I am wondering what the source of your information is. You could do it as simple as this:
$array = "nottestword","test_word15","test_word5","notatest" $array | where-object {$_ -like "test_word*"}
Jaap Brasser
http://www.jaapbrasser.com- Edited by Jaap Brasser Wednesday, May 30, 2012 10:25 AM
-
Wednesday, May 30, 2012 10:58 AM
Hi Jaap. Thanks for answer.
About your question I try to show all foldernames from Outlook account and show the number of emails in each folder. But i've stuck in one thing - excluding folder names which i don't need (calendar, deleted and a lot of manualy created).
Could you clarify a bit your example and help me further? (I'm not strong in it :). So as for now I need to find some sences
If objParent.Items.Count >=10 and objParent.Name <> "Deleted Items" and objParent.Name <> "Sent Items" and objParent.Name then objFile.Writeline "tada" Else ... End If
Could you fix it folowing your example please? It's a torture to enumerate all condition one by one... :)
- Edited by Roman Kuritsyn Wednesday, May 30, 2012 1:48 PM correct
- Edited by Roman Kuritsyn Wednesday, May 30, 2012 1:49 PM correct
- Edited by Roman Kuritsyn Thursday, May 31, 2012 8:03 AM
-
Friday, June 01, 2012 4:38 AMNobody ?
-
Friday, June 01, 2012 12:43 PMModerator
I am very suprised no one has suggested the use of a regular expression to solve this problem. I am not particullarly good at regular expressions, but wildcard searches are exactly what it's made for. I adapted the following example from the documentation for Windows Scripting Host ...
If objParent.Items.Count >=10 and not RegExpTest("Test_Wor*", objParent.Name) then ' do whatever end if ' Function RegExpTest(patrn, strng) Dim regEx ' Create variable. Set regEx = New RegExp ' Create regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Set case insensitivity. RegExpTest = regEx.Test(strng)' Execute the search test. End Function----------------
HTH,
Tom Lavedas
- Edited by Tom LavedasModerator Friday, June 01, 2012 12:47 PM to add a link to WSH docs
- Proposed As Answer by CountryStyle Friday, June 01, 2012 1:12 PM
- Marked As Answer by IamMredMicrosoft Employee, Owner Sunday, June 03, 2012 2:14 PM
- Unmarked As Answer by Roman Kuritsyn Monday, June 04, 2012 4:35 AM
- Unproposed As Answer by Roman Kuritsyn Monday, June 04, 2012 4:36 AM
-
Friday, June 01, 2012 1:13 PM
Here is a link for a VBS regex tutorial, Regex is the way to go:
-
Friday, June 01, 2012 2:32 PM
If objParent.Items.Count >=10 and InStr(objParent.Name,"Test_Wor") Then
' do something
We can vary instr to tell it to only check the first 8 characters if that is requires.
No need for any fancy code here. That is what InStr was created for. And don't forget InStrRev.
¯\_(ツ)_/¯
-
Friday, June 01, 2012 8:17 PMModerator
-
Monday, June 04, 2012 4:44 AM
Thank you Tom and all guys for time, but the problem hasn't fixed yet. I got your solution but it works strange... I tried to describe all exclusions, some of them works ("Mailbox - *"), some not. For example, I put "Deleted It*" but in result I see "Deleted Items" and "Sent Items" which both should be excluded.
I thought it happens because of SPACE in folder name, but no, it isn't a reason as I see. Why it happens, could you suggest me please what to do? How to avoid it?
P.S. If I put the whole name ("Deleted Items" for example, it excluded correctly).
Option Explicit Dim objOutlook, objNamespace, lngTotal, objFolder, dctExcluded, aExclude, item, objFSO, objFile aExclude = Array("Mailbox - *", "Conversation*", "*Failures", "Deleted It*", "Calendar", "RSS Feeds", "Drafts", "Contacts", "Tasks", "Journal", "Outbox","Quarantine","Junk*","Sync*") Set dctExcluded = CreateObject("Scripting.Dictionary") For Each item In aExclude dctExcluded.Add LCase(item),item Next Set objOutlook = CreateObject("Outlook.Application") Set objNamespace = objOutlook.GetNamespace("MAPI") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile("C:\file1.htm") objFile.Writeline "<meta http-equiv='cache-control' content='no-cache'><meta http-equiv='pragma' content='no-cache'><meta http-equiv='expires' content='-1'><META HTTP-EQUIV='REFRESH' CONTENT='10'><style type='text/css'>body {background-color:#F2F2F2;font-family:verdana} .red{color:white;background-color:#FF9966;font-weight:bold;font-size:12pt} .black{color:black;background-color:white;font-weight:normal;font-size:10pt} .total{font-weight:bold;font-size:18pt}</style><body bottommargin=0 leftmargin=0 topmargin=0 rightmargin=0 marginheight=0 marginwidth=0><table border=0><tr><td>" For Each objFolder In objNamespace.Folders Call EnumFolder(objFolder, 0) Next objFile.Writeline "<tr class=total><td>Total: " & CStr(lngTotal) & "</td></tr></table></body>" Sub EnumFolder(objParent, level) ' Recursive subroutine to count items in folders. Dim objSubFolder, tabs If Not dctExcluded.Exists(LCase(objParent.Name)) and objParent.Items.Count >=50 Then If objParent.DefaultItemType = 0 Then tabs = Left(vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab,level) If level = 0 Then tabs = "Data Store:" objFile.Writeline "<tr><td class=red>"& tabs & objParent.Name &"</td><td class=red>"& " (" & objParent.Items.Count & ")" &"</td></tr>" lngTotal = lngTotal + objParent.Items.Count End If ElseIf dctExcluded.Exists(LCase(objParent.Name)) and objParent.Items.Count <50 Then If objParent.DefaultItemType = 0 Then tabs = Left(vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab,level) If level = 0 Then tabs = "Data Store:" objFile.Writeline "<tr><td class=black>"& tabs & objParent.Name &"</td><td class=black>"& " (" & objParent.Items.Count & ")" &"</td></tr>" lngTotal = lngTotal + objParent.Items.Count End If End If For Each objSubFolder In objParent.Folders Call EnumFolder(objSubFolder, level + 1 ) Next End Sub
- Edited by Roman Kuritsyn Monday, June 04, 2012 4:49 AM
- Edited by Roman Kuritsyn Monday, June 04, 2012 5:06 AM correction
- Edited by Roman Kuritsyn Monday, June 04, 2012 5:08 AM
-
Monday, June 04, 2012 2:02 PM
Here is an example. Run it to see how to handle folder name filtering for a large number of varios names. You cannot use wild cards. YOu must use the exaact folder name. spaces are allowed. If you are trying to remove top level folders than you need to use the foll name. It wwill differ between users. It will be Joe Smit -Mailbox inmany cases because these are not really folders but they are 'stores'
Figure out how this works before you try to make it into a webpage. So far what you are trying to do is still very vague.
Option Explicit Dim objOutlook, objNamespace, lngTotal, objFolder, dctExcluded, aExclude, item aExclude = Array("Sent Items", "Deleted Items","RSS Feeds", "Drafts", "Outbox","Quarantine","Junk E-mail","Sync Issues") Set dctExcluded = CreateObject("Scripting.Dictionary") For Each item In aExclude dctExcluded.Add LCase(item),item Next Set objOutlook = CreateObject("Outlook.Application") Set objNamespace = objOutlook.GetNamespace("MAPI") For Each objFolder In objNamespace.Folders EnumFolder objFolder, 0 Next Wscript.Echo "Total: " & CStr(lngTotal) Sub EnumFolder(objParent, level) ' Recursive subroutine to count items in folders. Dim objSubFolder, tabs If Not dctExcluded.Exists(LCase(objParent.Name)) Then If objParent.DefaultItemType = 0 Then tabs = Left(vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab,level) If level = 0 Then tabs = "Data Store:" Wscript.Echo tabs & objParent.Name & " (" & objParent.Items.Count & ")" lngTotal = lngTotal + objParent.Items.Count End If End If For Each objSubFolder In objParent.Folders Call EnumFolder(objSubFolder, level + 1 ) Next End Sub
¯\_(ツ)_/¯
- Marked As Answer by Roman Kuritsyn Monday, June 04, 2012 3:22 PM
-
Monday, June 04, 2012 2:44 PM
You cannot use wild cards. YOu must use the exaact folder name. spaces are allowed. If you are trying to remove top level folders than you need to use the foll name. It wwill differ between users. It will be Joe Smit -Mailbox inmany cases because these are not really folders but they are 'stores'
So jrv, if I don't remove top level folder (Joe Smit - Mailbox), wildcards should work properly? Can I use them in this case?
I tried to remove it from Array and use wildcard "Sent It*" for example, but it doesn't work as well. Please be patient, I want clarify this thing :) My goal - to show minimum information - only needed folders which I need (exclude a trash via Array) and count emails in them)
-
Monday, June 04, 2012 3:10 PM
Wild cards will not work. Did you try the code I posted? YOu can reverse the logic and specify only required folders in teh array butt you canno use wild cards. If you want to use wild cards the code will have to be upgraded to use Regex.
¯\_(ツ)_/¯
- Marked As Answer by Roman Kuritsyn Monday, June 04, 2012 3:22 PM
-
Tuesday, June 05, 2012 4:32 AM
Dear ABQBill, I wrote here not via email, so such old and strange link above. And I as customer didn't sign off any SLA as well. I understand completely "These are just people who use Excel and help each other out in their spare time".
I suppose the goal of this resourse - to archieve maximum castomer satisfaction, am I right? If you know "then go to the official support team" path, please share it with us all. It would be more usefull than such "Copy-past style". Thank you.
-
Tuesday, June 05, 2012 5:06 PMModerator
I suppose the goal of this resourse - to archieve maximum castomer satisfaction, am I right?
Sorry for the misunderstanding. This is a peer-to-peer discussion forum. The point of the link to the blog post was to help you to understand that this is not an official support resource (even though Microsoft hosts it) and thus there is no guarantee that someone is going to supply an answer. We see lots of posts of people requesting that forum participants write code for them, and that is not the purpose of this forum. In general this forum exists to assist people with scripting questions, not to write customized scripting solutions for free. We don't have the resources to do that.
If you know "then go to the official support team" path, please share it with us all. It would be more usefull than such "Copy-past style". Thank you.
I would suggest that maybe support.microsoft.com would be a good place to start.
HTH,
Bill
-
Wednesday, June 06, 2012 4:48 AM
that this is not an official support resource (even though Microsoft hosts it)
There is not such termin as "oficial" or "not oficial". Look here - this forum IS a Microsoft Support Resource, FYI
We don't have the resources to do that.
Look, I don't demand the correct answer from any of guys here. I appreciate any help (especially from jrv who helps a lot without "it's not oficial resource" & "we lack of resources"). And I'm surpised your "freindly style", so please look here, let's hope it'll change your attitude towards consumers.
I would suggest that maybe support.microsoft.com would be a good place to start
Which service from there in particular, could you suggest me (sound like banishing from your side)? This is the way where I came from. And I know I can get support here - one of Microsoft Resources.
- Edited by Roman Kuritsyn Wednesday, June 06, 2012 4:48 AM
- Edited by Roman Kuritsyn Wednesday, June 06, 2012 5:08 AM
-
Wednesday, June 06, 2012 7:33 AM
Hi, I've a question here.
If I've a multiple mailbox (functional email) to choose from, and I chose one of the mailbox, how do I identify the mailbox name that I've chose? As I want to calculate the total number of emails that has 'sent on behalf of' (outbound email)?
I tried the codings as below:
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim sender As Outlook.AddressEntries
Dim olParentFolder, olFolderA As Outlook.MAPIFolder
Dim olMAPI As Object
Dim mymailbox As Object
Set olApp = CreateObject ("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")
Set olParentFolder = olNs.PickFolder
mymailbox = Application.GetNamespace("MAPI").GetDefaultFolder().Parent.Name
outbound_counter = 0
sender_name1 = sender_name.Value
For Each olFolderA In olParentFolder.Folders
Set email_Item = olFolderA.Items
For Each email_Item In olFolderA.Items
If email_Item.Class = olMail Then
sender_name2 = email_Item.SenderName
mymailbox = Application.GetNamespace("MAPI").GetDefaultFolder().Parent.Name
If mymailbox = sender_name2 Then
outbound_counter = outbound_counter + 1
End If
End If
-
Wednesday, June 06, 2012 9:32 AM
Candy18, Roman
Hi, I am going to use this opportunity to clarify Bill's position because what Candy has done is to prove one of his challenges.
Candy18 - the code you have posted is VBA and not VBScript. This forum is supposed to be for administrative scripting and that does not generally include VBA although I have found that the line is blurred in many cases.
Outlook management with VBA is more of a desktop issue and not as much a systems administration issue. Also most users her are not VB or VBA programmers but are Admins a support personnel who work at the system configuration and maintenance level. Most do not know or use VB or VBA in the daily activities. The VBA and Office developer forums are usually better equipped to handle VBA questions for any Microsoft Office component.
I post this to try and clarify why, when some post here, they may experience some push-back.
Candy18 - I understand that you need an answer but it appears that forum etiquette may require that you start a new post with your question. You should post it in the Office Outlook Developer Forum since it is specific to Outlook VBA.
I have suggested that someone add a button to the forum post that would allow us to split a post to another forum by using the current topic to embed a link then display the forum lookup page. I think this might be useful.
If we can get a moderator to split you question off to the Outlook VBA Developer Forum I can follow it over there and help you find an answer along with the other contributors to Office development.
If you want to start a post in that forum you can refer to this thread by including a link.
Actually I don’t see where the link is because your question is not at all related to this thread/topic. You are asking about determining other issues which may have nothing at all to do with Outlook but are aspects of Exchange. Not all of this information can easily be gleaned from Outlook mail items.
¯\_(ツ)_/¯
-
Wednesday, June 06, 2012 9:59 AMAlright! Cause I do not know where to post my question at! Thanks for the links. Will try to post my question there! (:
-
Wednesday, June 06, 2012 2:33 PMModerator
There is not such termin as "oficial" or "not oficial". Look here - this forum IS a Microsoft Support Resource, FYI
Hi,
We do understand that it is hosted by Microsoft. That doesn't mean that everyone is entitled to a response (remember that these forums are free). This is a peer-to-peer discussion list, and in that sense, it is not "official" (i.e., there is no service-level agreement). Sorry for the confusion.
Look, I don't demand the correct answer from any of guys here. I appreciate any help (especially from jrv who helps a lot without "it's not oficial resource" & "we lack of resources"). And I'm surpised your "freindly style", so please look here, let's hope it'll change your attitude towards consumers.
When you did not get an answer, you posted a follow-up response, that seems to demand an answer:
Nobody?
My response (the link to Raymond Chen's blog post) was intended to remind everyone that this forum is a peer-to-peer support forum on Microsoft's site and there is no service-level agreement. (Of course, it's also impolite to seem to demand answers from others who are helping you for free.)
As I said, please keep in mind that this forum is moderated by busy professionals who volunteer to help others for free. We like to help but many times we simply don't have the resources to guarantee an answer to every question.
HTH,
Bill
-
Wednesday, June 06, 2012 3:44 PM
1 - You're wrong, it has SLA, as MSDN and Microsoft Answers as well. FYI Just believe me coz I knew it from inside ;)
2 - Nobody? - it's a question, no demand. so please don't manipulate it
- Edited by Roman Kuritsyn Wednesday, June 06, 2012 3:44 PM
-
Wednesday, June 06, 2012 4:24 PMModerator
1 - You're wrong, it has SLA, as MSDN and Microsoft Answers as well. FYI Just believe me coz I knew it from inside ;)
Sorry; there's not an SLA for this forum. It's peer-to-peer. This means that we're glad to help, but there should not be any expectation that there is any kind of a guarantee that your question will be answered.
2 - Nobody? - it's a question, no demand. so please don't manipulate it
Notice the modesty with which I phrased my reply: It "seemed to demand an answer." My response was intended to educate that this kind of response is easily misunderstood. (If you like, substitute "demand" with "expectation of answer.")
HTH,
Bill
-
Wednesday, June 06, 2012 5:33 PM
Sory but it has SLA. You're probably know it only from one "moderator" side. Nevertheless it's public forum and not right place for MS metrics publishing. It's internal business information.
Please stop discussion, it's offtopic and seems like "the sickness of last message"
-
Wednesday, June 06, 2012 5:49 PMModerator
Sory but it has SLA. You're probably know it only from one "moderator" side. Nevertheless it's public forum and not right place for MS metrics publishing. It's internal business information.
Hi,
A service-level agreement (SLA) means there is an agreement between the requesting party (in this forum, the person asking a question) and the party offering a service (in this forum, moderators or others trying to answer the question). There is no such agreement in this forum as it is a completely free service that is moderated by volunteers.
Sorry about the confusion. Hope this helps.
Bill

