C
Curtis L. Guy
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>
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>