Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript open MSWord 2007 find/replace text 1

Status
Not open for further replies.

retro1one

IS-IT--Management
May 18, 2011
2
US
I've been running this VBSCRIPT code from within HTML to open & manipulate MSWord 2003 doc, but when MSOffice got updated to 2007, i can't make it to work in MSWord 2007. It only open a blank Word document. Not even opening the existing file. Can someone please help?

Code:
'Open existing Word Doc
	Const wdReplaceAll  = 2
	
	Set fso = CreateObject("Scripting.FileSystemObject") 
	Set objWord = CreateObject("Word.Application")
	objWord.Visible = True
	Set objDoc = objWord.Documents.Open("test.Doc")
	Set objSelection = objWord.Selection

'Find & Replace text within word Doc

	objSelection.Find.Text = "OLD-TEXT"
	objSelection.Find.Forward = TRUE
	objSelection.Find.MatchWholeWord = TRUE
	objSelection.Find.Replacement.Text = "NEW-TEXT
	objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll

objDoc.Display
 



hi,
Code:
Set objDoc = objWord.Documents.Open("test.Doc")
fully qualify your PATH and FILENAME.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks much SkipVought. That worked! (specifying the fully qualified path)

I appreciate the help...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top