Page 1 of 2 1 2 LastLast
Results 1 to 20 of 22

Thread: Dialog box for EditFind

  1. #1
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location

    Dialog box for EditFind

    Hi - my first time posting on this forum. I am using Word 2010.

    I am trying to write a macro which, at its completion, activates another document and then comes up with the EditFind dialog box (i.e., that would perform the exact same thing as if you were to type "Alt-E, F" in Word. The following is what I came up with:

    Windows("AnotherDocument.docx").Activate
    With Dialogs(wdDialogEditFind)
        .WholeWord = True
        .Display
    End With
    Apparently I don't know how to work properly with dialog boxes because this does not work ideally. The dialog box that comes up does the following:
    • Displays the message "Word found no items matching these criteria" even though no text to search has been entered.
    • Requires the user to carry forward the search clicking on "Find Next" or pressing "Alt-F", but doesn't allow the user to simply press "Enter."
    • After searching, comes up with a VBA error message if text is searched for and not found.

    I'd appreciate your help. Thanks!

  2. #2
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    It would probably be better if you described exactly what it is that you want to do. Using the built in dialogs, such as wdDialogEditFind, is not always the best way to do something from VBA.

    Also note that using

    Windows("AnotherDocument.docx").Activate
    could be unpredictable and it is better to declare a Document object variable that you set the the document upon which you want the action to take place.

  3. #3
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location
    It's hard to describe in much simpler terms what I am trying to do.

    Basically, I'm in a particular document in Word. I want to be able to enter a shortcut key (such as Ctrl-Y) which pulls up another active document, and then pull up the search dialog specifying whole words to be searched only. Then I can enter the search term desired and press Enter. That's it. This may seem too simple a task for a macro, but due to the extremely repetitive nature of the task I am performing, it would be very useful.

    Your note on Windows Activate not being reliable is well taken.

    Thanks.

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    I am not sure I would call using Activate unreliable (or "unpredictable"). I rarely use it myself as I prefer to action documents directly using document objects.

    I am not getting the errors you seem to be getting.

  5. #5
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    It wasn't the Activate that I was suggesting was unpredictable but using
    Windows("AnotherDocument.docx") and I agree it is far better to use document objects.

    Here, running

    With Dialogs(wdDialogEditFind) .WholeWord = True .Display End With
    Does cause the message "Word found no items matching these criteria" to be displayed in the Find dialog and Pressing Enter, even though the Find Next has the focus does not work. That is the case whether .Display or .Show is used.

    For what Kevinj wants to do, I would use an InputBox to get from the user the word that they to find in code such as:

    Selection.HomeKey wdStory
        Selection.Find.ClearFormatting
        With Selection.Find
        .Text = InputBox("Enter the word that you want to find.", "Find")
        .Forward = True
        .Wrap = wdFindContinue
        .MatchCase = False
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        End With
        Selection.Find.Execute

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    If you are going to do that it would be much better to not use Selection, but a range object of the document.

  7. #7
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location
    Doug and Fumei,

    Thanks for your contributions. I'll probably go with code similar to Doug suggested (unless someone comes up with a way to use wdDialogEditFind).

    Kevin

  8. #8
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location
    I tried Doug's suggestion. It works fine as far as it goes. However, I have a special problem in that I want to be able to type in special characters such as é and ō. The input box can't handle those characters (neither can the built-in Navigation find feature), which is one reason I was trying to use the dialog box.

    Also, the method doesn't handle repeated finds - I suppose the code could be altered to handle this.

    I hate to have anyone spend to much time on answering this, especially since it's just a short-term requirements I have. Thanks for the answers received again.

  9. #9
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    To insert é into and InputBox, hold down the Alt key and type 0233 on the numeric keypad. Then insert õ use 0245.

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    "which is one reason I was trying to use the dialog box." Really, you never mentioned it before.

  11. #11
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location
    Well, I still haven't given up completely on this. I tried two other commands:

    Application.Run macroname:="EditFind"
    and

    CommandBars.FindControl(ID:=141).Execute
    The "Application.Run macroname:" command works in Word 2007, but in Word 2010 it works just like the faulty "Dialogs(wdDialogEditFind)" command. (My guess is that one will also work in 2007, but I haven't tried it.) Why would these commands not work in 2010 as they did in 2007?

    The "CommandBars.FindControl" command works to bring up the Advanced Find dialog box - fine, but I don't know how to pre-program preferences (such as WholeWord:=True).

    Fumei - you were right. I forgot to mention the requirement to put in special characters - sorry.

    Doug - thanks for your correct suggestion to use Alt + numeric pad for special characters. Another thing I didn't explain (sorry again) was that I am using shortcut keys for the special characters (such as Ctrl-a for á, Ctrl-Shift-a for ā, etc.) for about 12 special characters, so using Alt+ numbers would be cumbersome.

    Thanks.

  12. #12
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    Maybe you need to take a step backwards and advise exactly what it is that you want done with the new document (rather than concentrate on the way in which you have tried, which does not seem to lead in the right direction).

    There may be other ways of achieving it.

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    Sorry, but

    "the faulty "Dialogs(wdDialogEditFind)" command"

    is incorrect. The dialog is NOT faulty. Your assumptions are.

  14. #14
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location
    Fumei,

    Doug said it didn't work either (see his March 8, 7:52 post).

    Just curious - did you test it on Word 2010 or an earlier version of Word? For me it does work on earlier versions of Word but not Word 2010. It's the Word 2010 "Dialogs(wdDialogEditFind)" that doesn't seem to work.

    Thanks.

  15. #15
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    Actually he said: "Using the built in dialogs, such as wdDialogEditFind, is not always the best way to do something from VBA. "

    which is not the same as saying it does not work. And even if it does not work in 2010, that also does not mean it is "faulty". MS chganged a bunch of things in 2010.

  16. #16
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location
    Thanks.

  17. #17
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    So you give up and just go someplace else. Cross-posted.

    You are not going to get the functionality you want. Use a userform as Doug suggested.
    Last edited by fumei; 03-26-2013 at 06:49 PM.

  18. #18
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...rd-2010-a.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  19. #19
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location

    Dialog Box for EditFind

    First, I apologize for the cross-posting. That was inconsiderate of me, as I was enlightened by the cross-posting message to see. I'll avoid doing that again.

    Second, although I couldn't find why the EditFind dialog box wouldn't work, I found a workaround and am sharing it here in case it of use to anyone else. It involves the CommandBars.FindControl command:

    Windows("My Document.docx").Activate
    With Selection.Find
        .Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .MatchCase = False
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    CommandBars.FindControl(ID:=141).Execute
    Again, I hope this might be useful to someone else, and again, I apologize for the cross-posting.

  20. #20
    VBAX Regular
    Joined
    Mar 2013
    Posts
    10
    Location

    Dialog Box EditFind

    On top of my other apologies, I formatted the last post wrong somehow and couldn't edit it (insufficient permissions or something). Here's another try:

    First, I apologize for the cross-posting. That was inconsiderate of me, as I was enlightened by the cross-posting message to see. I'll avoid doing that again.

    Second, although I couldn't find why the EditFind dialog box wouldn't work, I found a workaround and am sharing it here in case it of use to anyone else. It involves the CommandBars.FindControl command:


    Windows("My Document.docx").Activate
    With Selection.Find
        .Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .MatchCase = False
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    CommandBars.FindControl(ID:=141).Execute
    Again, I hope this might be useful to someone else, and again, I apologize for the cross-posting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •