Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

Using VBScipt to FIND text in MS Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Curtis L. Guy - 06 Sep 2005 00:24 GMT
I need some help with a script that I am using to open a Word document.

The script, as written, opens the word document okay.  I actually want to
open the document to the line of text that begins with the word
"Troubleshooting."  The FIND that is coded in the script does nothing - the
document is open at the beginning.

How can I code this script to locate or "FIND" a specific word or words?

Thanks for any help you can provide.

The code of the script follows:

<?xml version="1.0"?>

<?job error="true" debug="true"?>

<!--

TS_Text_Open.wsf

Open the troubleshooting notes Word document

Skip past copy/paste section to display troubleshooting notes

-->

<job>

<script language="VBScript">

<![CDATA[

' Force all variables to be defined

Option Explicit

Dim shellWSH, wordApp, fileSys

Dim fileName, wordFile, wordDoc

' Start Windows Script Host shell

Set shellWSH = WScript.CreateObject("WScript.Shell")

' Start file system

Set fileSys = WScript.CreateObject("Scripting.FileSystemObject")

' Create the Word application.

Set wordApp = WScript.CreateObject("Word.Application")

' Open the document.

fileName = "D:\TS_Text.doc"

Set wordFile = fileSys.GetFile(fileName)

Set wordDoc = wordApp.Documents.Open(wordFile.Path)

' Locate beginning of troubleshooting notes and tips

With wordDoc.Range.Find

   .Text = "Troubleshooting"

   .Forward=True

   .Execute

End With

' Make the document visible

wordApp.Visible = True

' Release the script host shell and the file system object

Set shellWSH = Nothing

Set fileSys = Nothing

' Leave the document open - following code left FYI

' Quit Word and release the objects

'wordApp.Quit

'Set wordApp = Nothing

'Set wordFile = Nothing

'Set wordDoc = Nothing

' Quit the script

WScript.Quit

]]>

</script>

</job>
Howard Kaikow - 06 Sep 2005 07:06 GMT
Steve Roman's book Writing Word Macros has a useful chapter on using Find.

See the list of Word VBA books at
http://www.standards.com/index.html?WordVBABooks

Signature

http://www.standards.com/; See Howard Kaikow's web site.

> I need some help with a script that I am using to open a Word document.
>
[quoted text clipped - 100 lines]
>
> </job>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.