193 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
IBM Champion!
Thu, Dec 15th 2016 6
From 3000 milliseconds to 200 to open a page: Speed up your Notes Client applications by discovering their bottlenecks.
Wed, Nov 30th 2016 10
Host your migrated Domino Data in Switzerland at ch.ldcvia.com
Mon, Nov 14th 2016 6
Why do Software Developers always squawk when inheriting a foreign codebase?
Tue, Oct 4th 2016 7
LDC Via is a dream destination for migrated Notes applications
Tue, Aug 30th 2016 3
Software is an iceberg. You’ll get hurt by the submerged parts.
Fri, Feb 19th 2016 6
getting git
Tue, Dec 22nd 2015 4
Top 10
From 3000 milliseconds to 200 to open a page: Speed up your Notes Client applications by discovering their bottlenecks.
Wed, Nov 30th 2016 10
Notes Client Performance optimization with Notes RPC Parser: new Version 1.0.13 available
Mon, Apr 7th 2014 9
Tim Tripcony’s incinerate function elegantly batch recycles Domino Objects in Java
Tue, Nov 4th 2014 9
Back from ICON UK with some goodies.
Fri, Oct 2nd 2015 8
Why do Software Developers always squawk when inheriting a foreign codebase?
Tue, Oct 4th 2016 7
calling Word’s Find and Replace using LotusScript
Fri, May 9th 2014 6
Installing OpenNTF Essentials with local web preview
Fri, May 2nd 2014 6
LotusScript Comment Templates for lsdoc.org (aka LotusScript.doc, aka Javadoc for LotusScript)
Mon, Mar 31st 2014 6
Software is an iceberg. You’ll get hurt by the submerged parts.
Fri, Feb 19th 2016 6
Host your migrated Domino Data in Switzerland at ch.ldcvia.com
Mon, Nov 14th 2016 6


calling Word’s Find and Replace using LotusScript
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
andrewmagerman    

There are two syntaxes to call OLE objects, one is using := like this:

Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="hi", ReplaceWith:="hello", Replace:=wdReplaceAll

Unfortunately LotusScript does not know how to deal with this, so you have to list the arguments exhaustively and in their correct order, including arguments which one does not really need.

Usually I can figure the syntax pretty quickly, but this one was really fiddly, so here is my function in all its glory.

I’ve tested it on Notes 9.0.1 and Word 2010, German version – YMMV.

'/*************************************************************************************
' * Function FindAndReplaceWithinWordOLEObject:A function to find and replace some string within an inputted word document.
' * This function has been written because the OLE Call to the function is complicated and LotusScript does not 
' * allow this syntax : .Execute FindText:="hi", ReplaceWith:="hello", Replace:=wdReplaceAll
' * @param varWordDocument a Word Document. (e.g. Application.ActiveDocument)
' * strFindThis the string I want to replace
' * strReplaceWithThis the replacement string
' * @return true if successful.
' * @author Andrew Magerman/Magerman/NotesNet
' * @version May 9, 2014
' *************************************************************************************/
Function FindAndReplaceWithinWordOLEObject(varWordDocument, strFindThis As String, strReplaceWithThis As String) As boolean
	
	On Error GoTo ErrorHandling

	Print "version 7"

	'documentation of these values at end of function	
	Dim FindText As Variant
	Dim MatchCase As Variant
	Dim MatchWholeWord As Variant
	Dim MatchWildcards As Variant
	Dim MatchSoundsLike As Variant
	Dim MatchAllWordForms As Variant
	Dim Forward As Variant
	Dim Wrap As Variant
	Dim SearchFormattting As Variant
	Dim ReplaceWith As Variant
	Dim ReplaceZeroOrOneOrAll As Variant
	
	FindText = strFindThis
	MatchCase = True
	MatchWholeWord = False
	MatchWildcards = False
	MatchSoundsLike = False
	MatchAllWordForms = False
	Forward = True
	
	'The folowing are the valid constants for Wrap
	'Const wdFindStop = 0
	'Const wdFindAsk = 2
	'Const wdFindContinue = 1	
	Wrap = 1
	
	SearchFormattting = True	
	ReplaceWith = strReplaceWithThis
	
	'The folowing are the valid constants for ReplaceZeroOrOneOrAll
	'Const wdReplaceAll = 2
	'Const wdReplaceNone = 0
	'Const wdReplaceOne = 1
	ReplaceZeroOrOneOrAll = 2 
	
	FindAndReplaceWithinWordOLEObject = varWordDocument.Content.Find.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, SearchFormattting, ReplaceWith, ReplaceZeroOrOneOrAll)
	
	Exit Function
Errorhandling:
	Call LogError()
	FindAndReplaceWithinWordOLEObject = false
	Exit Function
	%REM
	expression .Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)
	expression Required. A variable that represents a Find object.
	
	Parameters
	
	FindText
	Optional
	Variant
	The Text To be searched for. Use an empty String ("") To search For formatting only. You can search For special characters by specifying appropriate character codes. For example, "^p" corresponds To a paragraph mark And "^t" corresponds To a Tab character.
	
	MatchCase
	Optional
	Variant
	True To specify that the find Text be Case sensitive. Corresponds To the Match Case check box In the Find And Replace dialog box (Edit menu).
	
	MatchWholeWord
	Optional
	Variant
	True To have the find operation locate only entire words, Not Text that Is part of a larger word. Corresponds To the Find whole words only check box In the Find And Replace dialog box.
	
	MatchWildcards
	Optional
	Variant
	True To have the find Text be a special search operator. Corresponds To the Use wildcards check box In the Find And Replace dialog box.
	
	MatchSoundsLike
	Optional
	Variant
	True To have the find operation locate words that sound similar To the find text. Corresponds To the Sounds Like check box In the Find And Replace dialog box.
	
	MatchAllWordForms
	Optional
	Variant
	True To have the find operation locate all forms of the find Text (For example, "sit" locates "sitting" And "sat"). Corresponds To the Find all word forms check box In the Find And Replace dialog box.
	
	Forward
	Optional
	Variant
	True To search forward (toward the End of the document).
	
	Wrap
	Optional
	Variant
	Controls what happens If the search begins at a point other than the beginning of the document And the End of the document Is reached (Or vice versa If Forward Is Set To False). This argument also controls what happens If there Is a selection Or range And the search Text Is Not found In the selection Or range. Can be one of the WdFindWrap constants.
	
	Format
	Optional
	Variant
	True To have the find operation locate formatting In addition To, Or instead of, the find text.
	
	ReplaceWith
	Optional
	Variant
	The replacement text. To Delete the Text specified by the Find argument, Use an empty String (""). You specify special characters And advanced search criteria just As you Do For the Find argument. To specify a graphic object Or other nontext item As the replacement, move the item To the Clipboard And specify "^c" For ReplaceWith.
	
	Replace
	Optional
	Variant
	Specifies how many replacements are To be made: one, all, Or none. Can be Any WdReplace constant.
	
	MatchKashida
	Optional
	Variant
	True If find operations match Text With matching kashidas In an Arabic-language document. This argument may Not be available To you, depending On the language support (U.S. English, For example) that you have selected Or installed.
	
	MatchDiacritics
	Optional
	Variant
	True If find operations match Text With matching diacritics In a right-to-left language document. This argument may Not be available To you, depending On the language support (U.S. English, For example) that you have selected Or installed.
	
	MatchAlefHamza
	Optional
	Variant
	True If find operations match Text With matching alef hamzas In an Arabic-language document. This argument may Not be available To you, depending On the language support (U.S. English, For example) that you have selected Or installed.
	
	MatchControl
	Optional
	Variant
	True If find operations match Text With matching bidirectional control characters In a right-to-left language document. This argument may Not be available To you, depending On the language support (U.S. English, For example) that you have selected Or installed.
	
	MatchPrefix
	Optional
	Variant
	
	True To match words beginning With the search string. Corresponds To the Match prefix check box In the Find And Replace dialog box.
	MatchSuffix
	Optional
	Variant
	True To match words ending With the search string. Corresponds To the Match suffix check box In the Find And Replace dialog box.
	
	MatchPhrase
	Optional
	Variant
	True ignores all white Space And control characters between words.
	
	IgnoreSpace
	Optional
	Variant
	True ignores all white Space between words. Corresponds To the Ignore white-space characters check box In the Find And Replace dialog box.
	
	IgnorePunct
	Optional
	Variant
	True ignores all punctuation characters between words. Corresponds To the Ignore punctuation check box In the Find And Replace dialog box.
	
	Return Value
	Boolean
	
	%END REM
	
	
	
End Function



---------------------
http://blog.magerman.com/2014/05/09/calling-words-find-and-replace-using-lotusscript/
May 09, 2014
7 hits



Recent Blog Posts
6
IBM Champion!
Thu, Dec 15th 2016 12:21p   Andrew Magerman
A
10
From 3000 milliseconds to 200 to open a page: Speed up your Notes Client applications by discovering their bottlenecks.
Wed, Nov 30th 2016 4:22p   Andrew Magerman
A
6
Host your migrated Domino Data in Switzerland at ch.ldcvia.com
Mon, Nov 14th 2016 11:19a   Andrew Magerman
A
7
Why do Software Developers always squawk when inheriting a foreign codebase?
Tue, Oct 4th 2016 4:29a   Andrew Magerman
A
3
LDC Via is a dream destination for migrated Notes applications
Tue, Aug 30th 2016 8:49a   Andrew Magerman
A




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition