【发布时间】:2016-03-26 22:21:42
【问题描述】:
我正在使用以下 Excel VBA 代码在现有的当前幻灯片中插入当前日期。现在,我可以在第二个文本框中的 Powerpoint 幻灯片中插入当前日期,但我无法根据我的要求更改日期格式。日期显示为 2016 年 3 月 26 日,而我必须修改它,如 2015 年 3 月 26 日 请注意我不考虑在页脚处插入日期,我必须在文本框中添加日期。
Sub Date()
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim PPshape As PowerPoint.Shape
Dim objPPTX As Object
Dim Todate As Date
Todate = DateValue(Now)
Todate = Format(Todate, "mmmm d, yyyy")''tried this
'or this ?
Todate = Format(CDate(Todate), "mmmm d, yyyy")'''Tried this also
Application.DisplayAlerts = False
Set objPPTX = CreateObject("PowerPoint.Application")
objPPTX.Visible = True
objPPTX.Presentations.Open "path.pptx"
'Adding Date on First Slide
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
PPApp.Visible = True
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex) ''copy chart on existing slide
Set PPshape = PPSlide.Shapes.AddShape(Type:=msoShapeRectangle, Left:=220, Top:=150, Width:=270, Height:=75)
With PPshape
.Fill.ForeColor.RGB = RGB(115, 111, 112)
.TextFrame.TextRange.Text = Todate
Todate = Format(Todate, "mmmm d, yyyy")
'or this ?
Todate = Format(CDate(Todate), "mmmm d, yyyy")
.TextFrame.TextRange.Font.Name = "Arial"
.TextFrame.TextRange.Font.Color = vbYellow
.TextFrame.TextRange.Font.Size = 18
End Sub
【问题讨论】:
标签: vba excel powerpoint