Consulting

Results 1 to 4 of 4

Thread: VBA Problem: Inserting a header / footer

  1. #1

    Angry VBA Problem: Inserting a header / footer

    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?
    Last edited by iamthebest; 11-09-2008 at 01:02 AM.

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

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

    [/vba]works perfectly. At least, running from Word.

  3. #3
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    Question originally started here, 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!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Ah....

    Thanks for posting that Simon. Duly noted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •