【问题标题】:VBA code to change date format of PPT slide inside text boxVBA代码更改文本框内PPT幻灯片的日期格式
【发布时间】: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


    【解决方案1】:

    这是你的问题。您将文本框架的文本设置为 Todate,然后更改 Todate 的格式:

    .TextFrame.TextRange.Text = Todate
    Todate = Format(Todate, "mmmm d, yyyy")
    

    试试这个:

    .TextFrame.TextRange.Text = Format(Now, "mmmm dd, yyyy")
    

    【讨论】:

      【解决方案2】:

      针对你问题中提到的Excel VBA代码,解决方法可以如下例所示:

      Sub DisplayDate()
        Range("A1").Value = CDate(DateValue(Now))
        Range("A1").NumberFormat = "mmmm d, yyyy"
      End Sub
      

      【讨论】:

        猜你喜欢
        • 2023-02-10
        • 2013-04-09
        • 1970-01-01
        • 1970-01-01
        • 2011-02-27
        • 1970-01-01
        • 1970-01-01
        • 2022-06-10
        • 1970-01-01
        相关资源
        最近更新 更多