Results 1 to 3 of 3

Thread: MS Word 2010: Increment date in header of microsoft word

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    2

    Smile MS Word 2010: Increment date in header of microsoft word

    Hello,

    Thank you for reading my post. I know time is valuable thing when it comes to programing. I am not an expert but I know a bit about programming and currently stuck in a situation. I am trying to auto-increment date in header of Microsoft Word 2010 document for about 100 pages, pages could be less. Example:
    Page1 Header: Sunday, May 4th 2014
    Page2 Header: Monday, May 5th 2014
    Page3 Header: Tuesday, May 6th 2014 etc. until given page.

    The reason I want to put this in a header section of a document, because this date is repeating. If it can be placed automatically into every page with VB, that is also a solution for me.

    Here is what I have for code:

    Code:
    Sub EditHeadersAndFooters()
    
    Dim i As Long
    Dim mBefore As Date
    
    
    For i = 1 To ActiveDocument.Sections.Count
        With ActiveDocument.Sections(i)
           
       mBefore = Format(DateAdd("d", i, Date), "dd mmmm yyyy")
       
            .Headers(wdHeaderFooterPrimary).Range.Text = mBefore
            .Footers(wdHeaderFooterPrimary).Range.Text = foo
        End With
    Next
    
    End Sub
    This code works but it does not auto-increment the date. From code you can see that I am not an expert. However, if you can help me in a way that I can use your solution I will reward you, if you have pay-pal account.

    Thank you.

  2. #2
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: MS Word 2010: Increment date in header of microsoft word

    Hi,

    I don't have much to work on, but my first guess would be the header enum could be the wrong one for the type of sections on your document. Try changing wdHeaderFooterPrimary to one of the others (wdHeaderFooterFirstPage/wdHeaderFooterEvenPages). I would try wdHeaderFooterFirstPage first.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2014
    Posts
    2

    Re: MS Word 2010: Increment date in header of microsoft word

    I have found out why it does not work:

    Section headers are linked, which would cause them all to be the same.

    When you select a section's header, if it says "Same as Previous", then turn off the "Link to Previous" button. You'll need to check each section.

    However, this does not solve my problem

Posting Permissions

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



Click Here to Expand Forum to Full Width