I don’t have too much experience with VB Scripting but I’m trying to write something that will search for a specific string in a word document, replace it with whatever I specify and then print it out on a label printer.
It does the first replacement just fine, but not the second. Could anyone have a look and see what I might be doing wrong?
Option Explicit
Dim WordApp
Dim WordDoc
Dim strReadCompName
Dim strReadCompSN
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = TRUE
WordApp.Documents.Open("C:\LabelTemplate.doc")
WordApp.Documents("LabelTemplate.doc").Activate
Set WordDoc = WordApp.ActiveDocument
strReadCompName = InputBox("Enter Computer Name", "Name")
strReadCompSN = InputBox("Enter Serial Number", "Serial")
With WordApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = TRUE
.Text = "nametext"
.Execute ,,,,,,,,,strReadCompName
End With
With WordApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = TRUE
.Text = "serialtext"
.Execute ,,,,,,,,,strReadCompSN
End With
WordDoc.PrintOut()
WordDoc.Saved = TRUE
WordApp.Quit
Solved my own problem haha
Oracle Certified Professional was right. All I had to do was add another statement to move the cursor back to the beginning. I just added WordApp.Selection.GoTo 1 to the beginning.