none
Find Function Word 2013 Automation RRS feed

All replies

  • Hi Bob,

    I wrote a sample with find function using C# and it works well for me.

    public void Main()
    
            {
    
                object objMissing = Type.Missing;
    
                string documentPath = @"C:\Users\UserName\Desktop\testFind.docx";
    
                Word.Application app = new Word.Application();
    
                app.Visible = true;
    
                Word.Document doc= app.Documents.Open(documentPath);
    
                Word.Range rng = doc.Content;
    
                rng.Find.ClearFormatting();
    
    
                object findText = "Video";
    
                int textNum = -1;
    
                do
    
                {
    
                     textNum++;
    
                     if (textNum > 0)
    
                         rng.Font.Bold = 1;
    
                    rng.Find.Execute(ref findText, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing);
    
                   
    
                  
    
                }
    
                while (rng.Find.Found);
    
               
    
                Console.WriteLine("Find words:{0}",textNum);
    
                Console.Read();
    
                app.Quit();
    
            }

    Would you mind show some code snippet for us to reproduce this issue?

    In addition, links below may be helpful:
    How to: Programmatically Search for and Replace Text in Documents

    Find Object (Word)

    Best regards

    Fei


    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.


    Tuesday, April 15, 2014 9:43 AM
    Moderator
  • Hi Fei,

    Many thanks for your prompt reply.

    Here is some sample code (it's Visual C++ 6).

    Bob


    COleVariant vTrue((short)TRUE),

    vFalse((short)FALSE),     

    vOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

    BOOL retval; //Set the values from the dialog box

    UpdateData();

    COleVariant vSearchPhrase(m_csFindText);

    COleVariant vCaseSensitive;

    if(m_bCaseSensitive)

    vCaseSensitive = vTrue;

    else

    vCaseSensitive = vFalse;

    try {

    m_pOLEFindObj->SetWrap(1);

    if(bNext)

    {

    retval = m_pOLEFindObj->Execute(

    vSearchPhrase,

    vCaseSensitive,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vTrue, //Direction of search

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional);

    }

    else

    {

    retval = m_pOLEFindObj->Execute(

    vSearchPhrase,

    vCaseSensitive,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vFalse, //Direction of search

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional,

    vOptional

    );

    }

    }catch(COleException* e)

    {

    e->Delete();

    AfxMessageBox("Document has closed, search will no longer work.");

    OnOK();

    return FALSE;

    }

    return retval;




    Tuesday, April 15, 2014 11:36 AM
  • Hi Bob,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards

    Fei


    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, April 16, 2014 7:17 AM
    Moderator
  • Hi Bob,

    Could you please provide me the following details:

    1> What is version and bit of the Word application.

    2> What is version and bit of Operating system.

    3> Is the issue is occurring only with one user or multiple users are affected.

    4> Was it working before or it never worked.

    Your patience is appreciated.

    Regards,

    Monday, April 21, 2014 3:15 PM
    Moderator
  • Hi Bob,

    Could you please provide me the following details:

    1> What is version and bit of the Word application.

    Office 2013 64 bit

    2> What is version and bit of Operating system.

    Windows 8.1 64 bit

    3> Is the issue is occurring only with one user or multiple users are affected.

    Occurs with all users.  

    4> Was it working before or it never worked.

    Works fine on every version and bit of of Windows from XP and from Office 2000 to Office 2010.

    Your patience is appreciated.

    Regards,

    Hi,

    See responses above.

    Many thanks,

    Bob

    Tuesday, April 22, 2014 8:11 AM
  • Hi Bob,

    This seems to be an issue which requires an extensive troubleshooting.

    I would advise you to open a case with Microsoft where a dedicated engineer would help on the issue.

    I including the link from where you can open a case.

    http://support.microsoft.com/select/Default.aspx?target=assistance&sd=gn

    Regards,

    Thursday, April 24, 2014 2:35 PM
    Moderator
  • Hi Bob

    Exactly what error are you getting? And what call is triggering it (note: I'm not conversant with C++, but am interested in the exact property/method of the object model).

    There was another discussion this week about a problem using Range.Find in Word 2013 that had to do with searching text in a table with vertically merged cells. This has been confirmed as a bug and will be corrected in a future update, the work-around is to use Selection.Find. I have to wonder if yours is related and whether that workaround is valid for you (until the update is released).


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, April 24, 2014 4:18 PM
    Moderator