Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2017, 10:32 PM
caarodriguez caarodriguez is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Novice
Need help creating a document with 365 images, with a day of the year 2018 captioned on each image.
 
Join Date: Nov 2017
Posts: 5
caarodriguez is on a distinguished road
Post Need help creating a document with 365 images, with a day of the year 2018 captioned on each image.

Hi,

I am trying to create a christmas gift for my mom. I would like to insert 365 family photos into my word document and run a macro that will sequentially add captioned dates to each image. Basically an image for each day of 2018.




example..
photo 1 with caption January 1st 2018
photo 2 with caption January 2nd 2018
etc

Any help with this would be very much appreciated.
Reply With Quote
  #2  
Old 11-02-2017, 01:29 AM
gmayor's Avatar
gmayor gmayor is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Without knowing how the images are inserted it is something of a guess, but the following will insert the date in the required format after each image.

Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 02 Nov 2017
Dim iShp As Integer
Dim dStartDate As Date
Dim oRng As Range
Dim strDate As String
    dStartDate = "01/01/2018"
    For iShp = 1 To ActiveDocument.InlineShapes.Count
        strDate = Format((dStartDate + iShp), "mmmm d") & _
                DateOrdinal(Format((dStartDate + iShp), "d")) & _
                Format((dStartDate + iShp), " yyyy")
        Set oRng = ActiveDocument.InlineShapes(iShp).Range
        oRng.Collapse 0
        oRng.Text = vbCr & strDate & vbCr
        Set oRng = oRng.Paragraphs(2).Range
        oRng.Font.Size = 24
        oRng.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Next iShp
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-03-2017, 07:00 PM
caarodriguez caarodriguez is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Novice
Need help creating a document with 365 images, with a day of the year 2018 captioned on each image.
 
Join Date: Nov 2017
Posts: 5
caarodriguez is on a distinguished road
Default

Thanks, I tried it.

I get an error saying "DateOrdinal" Compile Error: sub or function not defined.

I use insert -> pictures to get the images into my document.
Reply With Quote
  #4  
Old 11-03-2017, 08:25 PM
macropod's Avatar
macropod macropod is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 7 64bit Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could add the following function to the same code module you use for Graham's code:
Code:
Function DateOrdinal(Val As Long) As String
Dim strOrd As String
If (Val Mod 100) < 11 Or (Val Mod 100) > 13 Then strOrd = Choose(Val Mod 10, "st", "nd", "rd") & ""
DateOrdinal = IIf(strOrd = "", "th", strOrd)
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-03-2017, 10:10 PM
caarodriguez caarodriguez is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Novice
Need help creating a document with 365 images, with a day of the year 2018 captioned on each image.
 
Join Date: Nov 2017
Posts: 5
caarodriguez is on a distinguished road
Smile

Thanks it works! Just one issue, the first image is dated January 2nd, 2018. Any idea how I can get it to start from January 1st?
Reply With Quote
  #6  
Old 11-03-2017, 10:17 PM
macropod's Avatar
macropod macropod is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 7 64bit Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could change:
dStartDate = "01/01/2018"
to:
dStartDate = CDate("01/01/2018") - 1
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 11-03-2017, 10:54 PM
macropod's Avatar
macropod macropod is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 7 64bit Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Here's a slightly different approach that centres the pics horizontally, adds the date to the next line of the same paragraph, and superscripts the ordinals.
Code:
Sub AddPicDatesBelow()
Application.ScreenUpdating = False
Dim iShp As Long, dStartDate As Date, oRng As Range, strOrd As String
dStartDate = CDate("01/01/2018") - 1
With ActiveDocument
  For iShp = 1 To .InlineShapes.Count
    dStartDate = dStartDate + 1
    strOrd = DateOrdinal(Format((dStartDate), "d"))
    Set oRng = .InlineShapes(iShp).Range
    With oRng
      .ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Collapse wdCollapseEnd
      .Text = Chr(11) & Format((dStartDate), "mmmm d") & strOrd & Format((dStartDate), " yyyy") & vbCr
      .Start = .Start + 1
      .Font.Size = 24
      .Start = .Start + InStr(.Text, strOrd) - 1
      .End = .Start + 2
      .Font.Superscript = True
    End With
  Next iShp
End With
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub

Function DateOrdinal(Val As Long) As String
Dim strOrd As String
If (Val Mod 100) < 11 Or (Val Mod 100) > 13 Then strOrd = Choose(Val Mod 10, "st", "nd", "rd") & ""
DateOrdinal = IIf(strOrd = "", "th", strOrd)
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 11-03-2017, 11:07 PM
gmayor's Avatar
gmayor gmayor is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
Originally Posted by caarodriguez View Post
Thanks, I tried it.
I get an error saying "DateOrdinal" Compile Error: sub or function not defined.
I use insert -> pictures to get the images into my document.
Apologies - I forgot to include the dateordinal function. Paul's alternative should work equally well.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #9  
Old 11-04-2017, 05:13 AM
caarodriguez caarodriguez is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Novice
Need help creating a document with 365 images, with a day of the year 2018 captioned on each image.
 
Join Date: Nov 2017
Posts: 5
caarodriguez is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Apologies - I forgot to include the dateordinal function. Paul's alternative should work equally well.
Thanks alot, it works really well. Is it possible to put the dates above the images instead of below?
Reply With Quote
  #10  
Old 11-04-2017, 05:57 AM
macropod's Avatar
macropod macropod is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 7 64bit Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub AddPicDatesAbove()
Application.ScreenUpdating = False
Dim iShp As Long, dStartDate As Date, oRng As Range, strOrd As String
dStartDate = CDate("01/01/2018") - 1
With ActiveDocument
  For iShp = 1 To .InlineShapes.Count
    dStartDate = dStartDate + 1
    strOrd = DateOrdinal(Format((dStartDate), "d"))
    Set oRng = .InlineShapes(iShp).Range
    With oRng
      .ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Collapse wdCollapseStart
      .Text = vbCr & Format((dStartDate), "mmmm d") & strOrd & Format((dStartDate), " yyyy") & Chr(11)
      .Start = .Start + 1
      .Font.Size = 24
      .Start = .Start + InStr(.Text, strOrd) - 1
      .End = .Start + 2
      .Font.Superscript = True
    End With
  Next iShp
End With
Set oRng = Nothing
Application.ScreenUpdating = True
End Sub

Function DateOrdinal(Val As Long) As String
Dim strOrd As String
If (Val Mod 100) < 11 Or (Val Mod 100) > 13 Then strOrd = Choose(Val Mod 10, "st", "nd", "rd") & ""
DateOrdinal = IIf(strOrd = "", "th", strOrd)
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 11-04-2017, 06:01 AM
gmayor's Avatar
gmayor gmayor is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Change
Code:
oRng.Collapse 0
to
Code:
oRng.Collapse 1
in my original macro thus

Code:
Option Explicit

Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 02 Nov 2017
Dim iShp As Integer
Dim dStartDate As Date
Dim oRng As Range
Dim strDate As String
    dStartDate = "31/12/2017"
    For iShp = 1 To ActiveDocument.InlineShapes.Count
        strDate = Format((dStartDate + iShp), "mmmm d") & _
                  DateOrdinal(Format((dStartDate + iShp), "d")) & _
                  Format((dStartDate + iShp), " yyyy")
        Set oRng = ActiveDocument.InlineShapes(iShp).Range
        oRng.Collapse 1
        oRng.Text = vbCr & strDate & vbCr
        Set oRng = oRng.Paragraphs(2).Range
        oRng.Font.Size = 24
        oRng.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Next iShp
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub

Private Function DateOrdinal(Val As Long) As String
Dim strOrd As String
    If (Val Mod 100) < 11 Or (Val Mod 100) > 13 Then strOrd = Choose(Val Mod 10, "st", "nd", "rd") & ""
    DateOrdinal = IIf(strOrd = "", "th", strOrd)
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #12  
Old 11-04-2017, 09:40 PM
caarodriguez caarodriguez is offline Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Windows 10 Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Office 2016
Novice
Need help creating a document with 365 images, with a day of the year 2018 captioned on each image.
 
Join Date: Nov 2017
Posts: 5
caarodriguez is on a distinguished road
Default

Thanks for all your help
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to search for a specific year from a table with year range? Wii Excel 0 05-05-2015 12:40 PM
How to calculate a rolling year-to-date percentage by quarter as the year progresses sleake Excel Programming 2 04-23-2015 11:51 AM
Need help creating a document with 365 images, with a day of the year 2018 captioned on each image. Need advice on creating new .pst files every year Rockitman31 Outlook 1 03-02-2013 08:00 AM
Creative Ways for a year-to-year comparison??? ridonkulous5 Excel 1 03-23-2011 04:49 PM
Referencing a Captioned Picture ComcoDG Word 0 11-10-2008 04:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft