Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: create vbs to add text to start of each page of word  (Read 2463 times)

0 Members and 1 Guest are viewing this topic.

petreli

    Topic Starter


    Rookie

    create vbs to add text to start of each page of word
    « 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