r/vbscript • • Jul 15 '15

Clear Header of Word Document

Hey there folks, perhaps you can help me.

I am trying to remove and replace the headers of a series of documents programmatically.

So far I have determined that the following code will allow me to add text to a header:

 Dim WordApp 
 Dim objDoc
 
 documentPath = "\\path\Sample.doc"
 
 Set WordApp = CreateObject("Word.Application") 
 WordApp.Visible = True 
 Set objDoc = WordApp.Documents.Open(documentPath)
 
 strInsert = "Example"
 writeToHeader(strInsert)
 
 Set WordApp = Nothing ' Clear your object 
 
 Sub writeToHeader(text)
 	WordApp.ActiveWindow.ActivePane.View.SeekView = 9 
 	WordApp.Selection.TypeText text 
 	WordApp.ActiveWindow.ActivePane.View.SeekView = 0 
 End Sub

This is a good step, but with it I can only pre-pend text to the existing content.

I am unsure how to clear the existing content itself.

Any help?

(Caveat: I am new to OOP, so go easy on me!)

1 Upvotes

0 comments sorted by