none
Adding wildcards to an existing find folders macro? RRS feed

  • Question

  • I found Michael Bauer's excellent find folders script early last summer and applied it to my Outlook 2010 at that time.** It's been a godsend, most esp. since it also has ability to activate the found folder.  It's super great and I'd like to take that into sublime by adding wildcards to before and after the spot where the user input text would go.  I can't figure out in the code how that would go, however.

    This is the FindFolder portion where I suspect adding a "prefix" and a "suffix" wildcard would make the user's life easier.  I remember I always ran into trouble in an Access solution until I added just such a thing.  Then the user only needs to worry about adding the search term they're concerned with and it'll work (currently, typing in a search term yields zero results even when one knows the folder exists.  And there is also no error message.)

    Public Sub FindFolder()
      Dim Name$
      Dim Folders As Outlook.Folders
    
      Set m_Folder = Nothing
      m_Find = ""
      m_Wildcard = False
    
    '  Name = InputBox("Find Folder Name (you must use wildcards, this does not search for parts of a folder without them):", "Search Folder")
      Name = InputBox("Find Folder Name:", "Search Folder")
      If Len(Trim$(Name)) = 0 Then Exit Sub
      m_Find = Name
    
      m_Find = LCase$(m_Find)
      m_Find = Replace(m_Find, "%", "*")
      m_Wildcard = (InStr(m_Find, "*"))
    
      Set Folders = Application.Session.Folders
      LoopFINDfolders Folders
    
      If Not m_Folder Is Nothing Then
        If MsgBox("Activate Folder: " & vbCrLf & m_Folder.FolderPath, vbQuestion Or vbYesNo) = vbYes Then
          Set Application.ActiveExplorer.CurrentFolder = m_Folder
        End If
      Else
        MsgBox "Not Found", vbInformation
      End If
    End Sub

    Earlier today I added the text to alert user to add wildcards but it would be better to add it into the code itself.  I commented that particular line out and put the regular line back in.

    Also, besides adding a prefix and suffix wildcard, if I can call them that, would there be a way to also add wildcards in between words???  Can that be included?

    What I mean is that say the user typed this into the search box:

    fiscal year end activities

    that Outlook would then search for this, instead, successfully:

    *fiscal*year*end*activities*

    ?

    Thank you!  Very much appreciated.

    Cheers.




    ** (I have this as listed source URL, but it doesn't give his name.  But I now there are quite a few references to the macro as it's posted a lot as a solution:  http://www.vboffice.net/en/developers/find-folder-by-name/?mnu=2&cmd=showitem).


    • Edited by SGFan Tuesday, March 10, 2015 10:38 PM
    Tuesday, March 10, 2015 10:30 PM

Answers

  • Hello SGFan,

    Did try to debug the code in the set-by-step manner?

    Also, besides adding a prefix and suffix wildcard, if I can call them that, would there be a way to also add wildcards in between words???  Can that be included?

    Yes, you can include wildcard characters where you need, not only the prefix and suffix. Be aware, you need to use the LIKE operator to get the wild characters working correctly. You can read more about possible characters on the Wildcard Characters used in String Comparisons page on MSDN.

    Wednesday, March 11, 2015 5:48 AM

All replies

  • Hello SGFan,

    Did try to debug the code in the set-by-step manner?

    Also, besides adding a prefix and suffix wildcard, if I can call them that, would there be a way to also add wildcards in between words???  Can that be included?

    Yes, you can include wildcard characters where you need, not only the prefix and suffix. Be aware, you need to use the LIKE operator to get the wild characters working correctly. You can read more about possible characters on the Wildcard Characters used in String Comparisons page on MSDN.

    Wednesday, March 11, 2015 5:48 AM
  • Hi SGFan,

    Base on my test with that code in Outlook2013, it works fine, for example:

    1. Type %ut%
    2. The result is [my alias]\Outbox

    There are some global variables, please define these variables before all functions.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 11, 2015 9:24 AM
    Moderator
  • Hi, guys.  Thanks so much for your responses.  Yes, I had a feeling that this could be done, of course, but not how.

    The confusing thing is that in the old ng days, we could wander into the vb for programmers newsgroup for Outlook and be welcomed in and helped out while still being just plain old users and not developers.  I guess it's understandable that everyone dropping in is assumed a programmer/developer type ... <lol> - but they send us over here from the users groups lickety-split, so what can I say ... ?  Once I have working code, I'm pretty good at then editing/recycling without much further hand-holding, but when it's something new, if I don't find a close example on the net and since vb is just not intuitive for me, I have to admit that I get stumped very quickly <sigh>.  I'm a power user office worker, not a programmer ... what can I say?! <g>

    Is there at least some starting out syntax that might help?  I google and google but, of course, don't get very far until I at least have a starting string to search for or an actual concrete example.

    Is there anything?  I get really bogged down when you guys send me to those instructional pages for developers.  Good thing my professional ego has at least 15 years of battering with regards to vb already ... <g>

    Thanks guys!  Any help really appreciated to at least have a simpler, beginner starting point! <g>

    Cheers.

    Wednesday, March 11, 2015 6:06 PM
  • Hi SGFan,

    For the non-program issue, you could post it to Outlook IT Pro Discussions forum.

    If you still want to achieve that programming, I suggest that you could learn outlook object model and VBA first.

    # Getting Started with VBA in Outlook 2010

    https://msdn.microsoft.com/en-us/library/office/ee814736%28v=office.14%29.aspx?f=255&MSPPError=-2147217396   

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 12, 2015 2:55 AM
    Moderator
  • SGFan,

    You may find the following articles in MSDN helpful:

    Getting Started with VBA in Office 2010

    Getting Started with VBA in Outlook 2010

    See the Outlook Solutions section in MSDN for more information.

    Thursday, March 12, 2015 12:49 PM
  • Oh, um, thanks, Eugene <sigh>.

    Thanks for everyone's advice re learning vba.  I've been slowly learning over the years but I've really been there and done that with all those "learn vba"" sites I've ever looked at.  One gets bogged down so very quickly.  You have to sift through so much, you see, and weed out what is relevant and what is not.  I handle other more intuitive scripting and macro languages just fine, it's vb that just has something that makes it tough.  I also have a full time job that requires an hour to 3 of unpaid overtime every workday for me to keep up (they don't have enough staff).  And this all takes away from the time I do have (though this is that important).

    This is a macro that impacts me all the time.  I'm trying to find a way to find things fast and reliably as the "new" Outlook's features are not as strong as they used to be to either navigate quickly around Outlook or to find things quickly and reliably.  I just need to find out syntax to allow me to add a wildcard before and after where the user would input text.

    <sigh>

    Have a good day, everybody.  Going to have to leave this for now and to try to remember to add the wildcards in myself every time I use it.  Also, hopefully my next google searches for this will provide me with more information and if I'm very lucky, actual example syntax.  Well, it does happen sometimes though the searching takes a long time.

    Thank you.

    Thursday, March 12, 2015 4:52 PM
  • Hi SGFan,

    In my opinion, the samples on the internet is better for us to learn, we need base on our detail requirement to modify it or we need to deal with the errors, so I don’t recommend that we use it directly without know how it works and how to modify.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, March 13, 2015 1:54 AM
    Moderator