vb.net Word 2007 versioning problem

J

JensB

I got a VB VS2005 App, automating Word version 2000 and 2003. Code works
fine with these Office versions.

Now one user installed Office 2007.
He starts getting an error in this part of the code:

WRD.Selection.Find.Execute(Bookmark, , , , , , True, wdFindContinue, ,
Insertvalue)

Strange this is the only command, that doesn't work of all various commands
in use.

Any Workaround or solution much appreciated.

\JensB
 
D

Doug Robbins - Word MVP

I gather that what your code is doing is inserting something into a
bookmark.

I would do that by using the range of the bookmark

WRD.Bookmarks("[bookmarkname]").Range.InsertBefore

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JensB

Doug Robbins - Word MVP said:
I gather that what your code is doing is inserting something into a
bookmark.

I would do that by using the range of the bookmark

WRD.Bookmarks("[bookmarkname]").Range.InsertBefore

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Sorry, a bad habbit from my side using Bookmark as variable name. Code
should look like this:
(I am not using bookmarks.)

word.selection.Find.Execute(FindText, , , , , , True, wdFindContinue, ,
Insertvalue)

JensB
 
J

Jean-Guy Marcil

JensB was telling us:
JensB nous racontait que :
I got a VB VS2005 App, automating Word version 2000 and 2003. Code
works fine with these Office versions.

Now one user installed Office 2007.
He starts getting an error in this part of the code:

WRD.Selection.Find.Execute(Bookmark, , , , , , True, wdFindContinue, ,
Insertvalue)

Strange this is the only command, that doesn't work of all various
commands in use.

Any Workaround or solution much appreciated.

Instead of using:
WRD.Selection.Find.Execute(Bookmark, , , , , , True, wdFindContinue,
,Insertvalue)
try writing the parameter name and remove the superfluous commas (in Word
2007 you are missing a few commas and it may well be that Word 2007 is more
rigorous and expect all commas to be there.)
WRD.Selection.Find.Execute(FindText:=Bookmark, etc.)


From the MSDN web site:

Word 2002 Execute method as it applies to the Find object:
expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards,
MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith,
Replace,
MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)

(http://msdn2.microsoft.com/en-us/library/aa201472(office.10).aspx#)


Word 2007 Execute method as it applies to the Find object:
expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards,
MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith,
Replace,
MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl,
MatchPrefix, MatchSuffix, MatchPhrase, IgnoreSpace, IgnorePunct)

(http://msdn2.microsoft.com/en-us/library/bb179352.aspx)

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

JensB said:
Doug Robbins - Word MVP said:
I gather that what your code is doing is inserting something into a
bookmark.

I would do that by using the range of the bookmark

WRD.Bookmarks("[bookmarkname]").Range.InsertBefore

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Sorry, a bad habbit from my side using Bookmark as variable name. Code
should look like this:
(I am not using bookmarks.)

word.selection.Find.Execute(FindText, , , , , , True, wdFindContinue, ,
Insertvalue)

You're much less likely to run into problems like this if instead of using
empty arguments, you use named arguments, like this.

word.selection.Find.Execute(FindText:=FindText, Forward:=True,
Wrap:=wdFindContinue, ReplaceWith:=Insertvalue)

Working this way means that you are not vulnerable to Microsoft adding new
arguments somewhere in the middle of the list or changing the order, but
only to Microsoft actually changing the name or operation of an existing
argument. Don't make it easier than necessary for Microsoft to break your
code!
 
J

JensB

Jonathan West said:
JensB said:
Doug Robbins - Word MVP said:
I gather that what your code is doing is inserting something into a
bookmark.

I would do that by using the range of the bookmark

WRD.Bookmarks("[bookmarkname]").Range.InsertBefore

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Sorry, a bad habbit from my side using Bookmark as variable name. Code
should look like this:
(I am not using bookmarks.)

word.selection.Find.Execute(FindText, , , , , , True, wdFindContinue, ,
Insertvalue)

You're much less likely to run into problems like this if instead of using
empty arguments, you use named arguments, like this.

word.selection.Find.Execute(FindText:=FindText, Forward:=True,
Wrap:=wdFindContinue, ReplaceWith:=Insertvalue)

Working this way means that you are not vulnerable to Microsoft adding new
arguments somewhere in the middle of the list or changing the order, but
only to Microsoft actually changing the name or operation of an existing
argument. Don't make it easier than necessary for Microsoft to break your
code!


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Good point Jonathan, !
I admit it is very slappy code, done for some years ago.
I will follow your advise
thks.
JensB
 
J

JensB

Jean-Guy Marcil said:
JensB was telling us:
JensB nous racontait que :


Instead of using:
WRD.Selection.Find.Execute(Bookmark, , , , , , True, wdFindContinue,
,Insertvalue)
try writing the parameter name and remove the superfluous commas (in Word
2007 you are missing a few commas and it may well be that Word 2007 is
more rigorous and expect all commas to be there.)
WRD.Selection.Find.Execute(FindText:=Bookmark, etc.)


From the MSDN web site:

Word 2002 Execute method as it applies to the Find object:
expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards,
MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith,
Replace,
MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)

(http://msdn2.microsoft.com/en-us/library/aa201472(office.10).aspx#)


Word 2007 Execute method as it applies to the Find object:
expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards,
MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith,
Replace,
MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl,
MatchPrefix, MatchSuffix, MatchPhrase, IgnoreSpace, IgnorePunct)

(http://msdn2.microsoft.com/en-us/library/bb179352.aspx)

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
Thanks to Jean-Gay
for your input as well, very helpful.
JensB
 

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