Computer Hope

Microsoft => Microsoft DOS => Topic started by: petreli on December 22, 2008, 05:11:30 AM

Title: create vbs to add text to start of each page of word
Post by: petreli on December 22, 2008, 05:11:30 AM
Can some help me change the follow vbs script to add the text "start" and "end" to each page of an existing multiple page doc.

the text also formated into white colour

   

strDocument = "c:\document.doc"
 
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open(strDocument)
Set objSelection = objWord.Selection
 
intLine = 1
intTotal = objDoc.Paragraphs.Count
 
For i = 1 To intTotal
   If i > 8 Then
      strPrepend = "| abc | " & intLine & " | L "
      startRange = objDoc.Paragraphs(i).Range.Start
      endRange = objDoc.Paragraphs(i).Range.End
      Set tRange = objDoc.Range(startRange, endRange)
      strLine = tRange.Text
      strLine = Left(strLine, Len(strLine) - 1)
      If strLine = "" Then
         tRange.Text = strPrepend & vbCrLf
      Else
         tRange.Text = strPrepend & strLine & vbCrLf
      End If
      intLine = intLine + 1
   End If
Next
 
objDoc.Save
objWord.Quit