簡體   English   中英

用於更改文本框內 PPT 幻燈片的日期格式的 VBA 代碼

[英]VBA code to change date format of PPT slide inside text box

我正在使用以下 Excel VBA 代碼在現有的當前幻燈片中插入當前日期。 現在,我可以在第二個文本框中的 Powerpoint 幻燈片中插入當前日期,但我無法根據我的要求更改日期格式。日期顯示為 3/26/2016 而我必須像 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

與您的問題中提到的 Excel VBA 代碼相關,解決方案可以如下例所示:

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

這是你的問題。 您將文本框的文本設置為 Todate,然后更改 Todate 的格式:

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

而是試試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM