Share via

macro for inserting batch dates?

Anonymous
2010-06-26T12:14:52+00:00

I need to add the date in a header of a word document - this document is 365 pages long - one page for each day of the year, and at present, am changing dates manually which is very time consuming.

The set up is a workbook, so month by month would probably be easier - is it possible to insert a date for a month in the format 1st July 2010 - through to 31st - and so on for each month

I hope this makes sense

I would be really grateful for any help with this

Many thanks

Jean

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2010-06-27T05:06:05+00:00

    Send the document to the link on the home page of my web site.

    <jeanmhealy> wrote in message news:*** Email address is removed for privacy ***...

    Thanks for replying so quickly Graham

    I believe the macro that you kindly sent above would create 365 blank pages, for you then to add the content.

    If i have grasped correctly, then I believe it would be better to add to existing document, this would be the 365 page whole year one, I am assuming that if would be as easy to do the whole year as a month

    I can send you a document (just the one page) which would be reproduced within the document 365 times?

    Thanks again for your help

    Jean


    Graham Mayor - Word MVP

    www.gmayor.com

    Posted via the Communities Bridge

    http://communitybridge.codeplex.com/

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-06-26T14:14:57+00:00

    Thanks for replying so quickly Graham

    I believe the macro that you kindly sent above would create 365 blank pages, for you then to add the content.

    If i have grasped correctly, then I believe it would be better to add to existing document, this would be the 365 page whole year one, I am assuming that if would be as easy to do the whole year as a month

    I can send you a document (just the one page) which would be reproduced within the document 365 times?

    Thanks again for your help

    Jean

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-06-26T13:17:57+00:00

    Page is a vague concept in Word and the whole point of headers is that they produce the same content across a range of pages. How easy what you intend will be to do is determined by how the document is currently set up. How have you created the new pages?

    If you were starting from scratch, you could use a macro to create the 365 pages using next page section breaks and add the date to the header of each section. The following macro will do that - note that it will take a while to run as it has to separately process 365 pages!

    If you need it to work with your existing document we would need to know more about what it contains, how the separate pages were created and what is already present in the header.

    http://www.gmayor.com/installing_macro.htm

    Option Explicit

    Sub Create365DatedPages()

    Dim i As Long

    Dim oDoc As Document

    Dim oSection As Section

    Dim oHeader As HeaderFooter

    Dim sDay As String

    Dim sOrd As String

    Dim dDate As Date

    Dim oRng As Range

    Set oDoc = Documents.Add

    For i = 1 To 364

        oDoc.Range.InsertBreak wdSectionBreakNextPage

    Next i

    For Each oSection In oDoc.Sections

        dDate = Date + oSection.Index - 1

        sDay = Format(dDate, "dd")

        Select Case Right(sDay, 1)

            Case Is = 1

                If Left(sDay, 1) = 1 Then

                    sOrd = "th"

                Else

                    sOrd = "st"

                End If

            Case Is = 2

                If Left(sDay, 1) = 1 Then

                    sOrd = "th"

                Else

                    sOrd = "nd"

                End If

            Case Is = 3

                If Left(sDay, 1) = 1 Then

                    sOrd = "th"

                Else

                    sOrd = "rd"

                End If

            Case Is = 4, 5, 6, 7, 8, 9, 0

                    sOrd = "th"

            Case Else

        End Select

        oSection.Headers(wdHeaderFooterPrimary).LinkToPrevious = False

        Set oRng = oSection.Headers(wdHeaderFooterPrimary).Range

        With oRng

            .Font.name = "Times New Roman"

            .Font.Size = 18

            .Font.Italic = True

            .Text = Format(dDate, "d")

            .Start = oSection.Headers(wdHeaderFooterPrimary).Range.End

            .Text = sOrd

            .Font.Superscript = True

            .Start = oSection.Headers(wdHeaderFooterPrimary).Range.End

            .Text = Format(dDate, " MMMM yyyy")

            .Font.Superscript = False

        End With

    Next oSection

    End Sub

    <jeanmhealy> wrote in message news:*** Email address is removed for privacy ***...

    I need to add the date in a header of a word document - this document is 365 pages long - one page for each day of the year, and at present, am changing dates manually which is very time consuming.

    The set up is a workbook, so month by month would probably be easier - is it possible to insert a date for a month in the format 1st July 2010 - through to 31st - and so on for each month

    I hope this makes sense

    I would be really grateful for any help with this

    Many thanks

    Jean


    Graham Mayor - Word MVP

    www.gmayor.com

    Posted via the Communities Bridge

    http://communitybridge.codeplex.com/

    Was this answer helpful?

    0 comments No comments