Word 2007 Find Parameters

M

Mark Wilson

In word 2007 the Find command has options "Ignore punctuation characters" and
"Ignore white-space characters". I'd like to be able to use the Word Object
Model to search a Range in a document for a text string and ignore any white
space characters. However, I can't seem to find any parameters for the
Execute method that will enable this option. How can I accomplish this
programmatically?

I can paste my own text into the document, but occasionally Word reformats
the text changing some spaces to non-breaking spaces or putting a space
before a CR/LF at the end of a line. I need to search for the text inserted
and remove it, but the Find command fails because Word has modified the
inserted text.
 
W

Wei Lu [MSFT]

Hello Mark,

In Word Object Model, there is no method and option to use the ignore white
space characters.

I am performing some research on the workaround, I appreciated your
patience.

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

Wei Lu [MSFT]

Hello Mark,

I found that the Find.IgnoreSpace property is which you are looking for.

Please have a try and let me know the result.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Thanks Wei.

I think my problem was that I was searching for answers in the MSDN library.
After reading your last note I used the Object Browser in Word 2007 and
found an Execute2007 method. It has 5 more parameters than Execute.

MatchPrefix
MatchSuffix
MatchPhrase
IgnoreSpace
IgnorePunct

That will probably solve the problem once I get the Word Object Library
imported. I'll explain the errors in my next message.
 
M

Mark Wilson

I'm programming my COM Addin in C++ and I need to import the Word 2007 OLB.
[I had previously imported the Word 2000 OLB without any problems]. However
I seem to be getting errors as follows:


msword.tlh(20906) : error C2146: syntax error : missing ';' before
identifier 'VBE'

msword.tlh(20906) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int

msword.tlh(21103) : error C2146: syntax error : missing ';' before
identifier 'GetVBE'

msword.tlh(21103) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int

msword.tlh(21103) : warning C4183: 'GetVBE': missing return type; assumed to
be a member function returning 'int'

msword.tlh(22289) : error C2146: syntax error : missing ';' before
identifier 'VBE'

msword.tlh(22289) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int

msword.tlh(22289) : error C2208: 'Word::VBE' : no members defined using this
type


My import looks like this:

#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll" \
rename_namespace("Office"), rename("DocumentProperties", "DocProps")
rename("RGB", "RGB_")

#import "C:\Program Files\Microsoft Office\Office12\MSWORD.OLB" \
rename("ExitWindows", "WordExitWindows") rename("FindText", "WordFindText")

#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"

#import "C:\Program Files\Microsoft Office\Office12\MSOUTL.OLB" \
rename_namespace("Outlook"), rename("CopyFile", "CopyFile_")
rename("PlaySound", "PlaySound_")

Is there a specifc order that should be used for importing the files ?

Any idea what I might have done wrong?

Thanks.
 
W

Wei Lu [MSFT]

Hello

My suggestion is import the lib not the olb directly.

You could use like following:

#import "libid:AC0714F2-3D04-11D1-AE7D-00A0C90F26F4" version("1.0")
lcid("0") raw_interfaces_only named_guids
//The following #import imports the MSO interface based on it's LIBID
#import "libid:2DF8D04C-5BFA-101B-BDE5-00AA0044DE52" version("2.4")
lcid("0") raw_interfaces_only named_guids auto_rename

Please refer this article:

http://groups.google.com/group/microsoft.public.office.developer.com.add_ins
/browse_thread/thread/543251ea1a391846/ea65f0e8422316b7?lnk=st&q=%22%23impor
t%22+%22v-phuang%22+libid&rnum=1&hl=en#ea65f0e8422316b7

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Thanks Wei.

I'll give that a try. However, just to answer my previous question I did
get the code to compile with this:

#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\mso.dll" \
rename("RGB", "RGB_")
using namespace Office;
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
#import "C:\Program Files\Microsoft Office\Office12\MSWORD.OLB" \
rename("ExitWindows", "WordExitWindows")
#import "C:\Program Files\Microsoft Office\Office12\MSOUTL.OLB" \
rename("CopyFile", "CopyFile_")
 
W

Wei Lu [MSFT]

Hello Mark,

Thanks for the update.

The issue is related with the conflict with the object in the import dll.

If you have any question, please feel free to let me know.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Wei, I'm still having problems with Find and IgnoreSpace.

From the Word 2007 Object Browser I see

Function Execute2007([FindText], [MatchCase], [MatchWholeWord],
[MatchWildcards], [MatchSoundsLike], [MatchAllWordForms],
[Forward], [Wrap], [Format], [ReplaceWith], [Replace],
[MatchKashida], [MatchDiacritics], [MatchAlefHamza],
[MatchControl], [MatchPrefix], [MatchSuffix], [MatchPhrase],
[IgnoreSpace], [IgnorePunct]) As Boolean
Member of Word.Find

I have set all variables to VT_ERROR except for

vtFindText.vt = VT_BSTR;
vtFindText.bstrVal = ::SysAllocString(L"Test");

vtForward.vt = VT_BOOL;
vtForward.boolVal = FALSE;



This runs without error. However when I try to use IgnoreSpace
I set it as follows:

vtIgnoreSpace.vt = VT_BOOL;
vtIgnoreSpace.boolVal = TRUE;

At run time Execute2007 fails with code 0x80020008 (Bad variable type)

If I set the values as follows:

vtIgnoreSpace.vt = VT_ERROR;
vtIgnoreSpace.scode = DISP_E_PARAMNOTFOUND;

It does not cause an error.

If not VT_BOOL, what should IgnoreSpace be?
 
L

Luke Zhang [MSFT]

Hi Mark,

There is few document about the Execute2007 method now. Have you tried set
the IgnoreSpace property of Find object and use its Execute method?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Wilson

Luke, that fixed it.

If I set the IgnoreSpace property of Find object and use its Execute method
instead of using Execute2007 it does not crash.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top