PDA

View Full Version : VBA Problem: Inserting a header / footer



iamthebest
11-09-2008, 12:41 AM
Private Sub UserForm_Click()

Dim section As Microsoft.Office.Interop.Word.sections 'error here


For Each section In Me.sections
section.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary) _
.Range.Text = "Confidential"
Next


End Sub


Keeps giving me a "user defined type not defined" error.. suggestions anyone?

fumei
11-09-2008, 08:46 AM
What is Me? Within Word itself, this only applies for procedures in THisDocument. Where is this code?

Why are you using interop?

What version of Word are you using? Try to always mention this when you post.

What application are you running it from?

A Type error is just that. It means either:

the type is not valid, or the syntax is incorrect.

Generally, it is not difficult to put text into headers (like you appear to trying to do) with VBA.


Dim oSection As Section
For Each oSection In ActiveDocument.Sections
oSection.Footers(wdHeaderFooterPrimary).Range.Text = "Confidential"
Next

works perfectly. At least, running from Word.

Simon Lloyd
11-09-2008, 05:19 PM
Question originally started here (http://vbaexpress.com/forum/showthread.php?t=23411), this question is related to a university assignment and as such we cannot give you direct help but rather "guide" you in the right direction!

fumei
11-10-2008, 12:41 PM
Ah....

Thanks for posting that Simon. Duly noted.