PDA

View Full Version : [SOLVED:] Inserting today's date on a slide



RayKay
08-23-2019, 07:01 AM
Hi John

The way our template works, it uses the Footer filed in PowerPoint with a classification inserted. This stops the date being added using the Header & Footer tool.

I got as far as a text box going onto the slide, but I can't get the date to appear in the next text box.
I don't want the date to update, just to show today's date when the macro is used.

Can you help? Thanks. Have a wonderful long weekend.





Sub AddDate()
Dim StickerText As StringDim Sld As Slide
StickerText = "ppDateTimeHmm"
Dim shp As Shape
For Each Sld In ActiveWindow.Selection.SlideRange
Set shp = Sld.Shapes.AddShape(Type:=msoShapeRectangle, _ Left:=26 * 28.3464567, Top:=0 * 28.3464567, Width:=80, Height:=26.6)
shp.Name = "Dated" shp.Line.visible = msoFalse shp.Fill.ForeColor.RGB = RGB(255, 255, 255) shp.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0) shp.TextFrame.TextRange.Characters.Text = StickerText shp.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter shp.TextFrame.TextRange.Paragraphs.ParagraphFormat.SpaceBefore = 0 shp.TextFrame.TextRange.Paragraphs.ParagraphFormat.SpaceAfter = 0 shp.TextFrame2.VerticalAnchor = msoAnchorMiddle shp.TextFrame2.TextRange.Font.Size = 10 shp.TextFrame2.TextRange.Font.Name = "Arial" shp.Rotation = 0
Next Sld
End Sub

Paul_Hossler
08-23-2019, 07:33 AM
If I'm understanding correctly ...




Option Explicit


Sub AddDate()
Dim oSlide As Slide
Dim oShape As Shape
For Each oSlide In ActiveWindow.Selection.SlideRange

For Each oShape In oSlide.Shapes
If oShape.Name = "Dated" Then
oShape.Delete
Exit For
End If
Next

Set oShape = oSlide.Shapes.AddShape(Type:=msoShapeRectangle, Left:=26 * 28.3464567, Top:=0 * 28.3464567, Width:=80, Height:=26.6)

With oShape
.Name = "Dated"
.Line.Visible = msoFalse
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
.TextFrame.TextRange.Characters.Text = Format(Now, "Short Date")
.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
.TextFrame.TextRange.Paragraphs.ParagraphFormat.SpaceBefore = 0
.TextFrame.TextRange.Paragraphs.ParagraphFormat.SpaceAfter = 0
.TextFrame2.VerticalAnchor = msoAnchorMiddle
.TextFrame2.TextRange.Font.Size = 10
.TextFrame2.TextRange.Font.Name = "Arial"
.Rotation = 0
End With
Next oSlide
End Sub

RayKay
08-27-2019, 01:34 AM
Perfect, thanks Paul :)