2016-03-26 20 views
0
Geçerli güç noktası slaytı mevcut güncel tarihi eklemek için Excel VBA Code aşağıdaki kullanıyorum

içine PPT slayt tarih biçimini değiştirmek için. Şu anda, 2 metin kutusuna Powerpoint slayt güncel tarihi ekleyebilirsiniz ama lütfen unutmayın 26 Mart 2015 gibi değiştirmek için varken benim requirement.Date 3/26/2016 gibi görünen başına ben tarih biçimini değiştiremiyoruz Ben altbilgi kenarındaki tarih bilgisi eklemeyle ilgili almıyorum, ben Metin kutusuna tarih eklemek zorunda. Sorunuza belirtilen Excel VBA koduna ihtiyaç duyulanVBA kodu metin kutusuna

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 

cevap

0

İşte senin sorunun. Sen Todate metin çerçevesinin metin ayarlama ve SONRA Todate biçimlendirmesini değiştiriyoruz:

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

yerine bu deneyin:

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

Thanks..Works harika – Muneeb

0

, çözüm olarak aşağıdaki örnekte gösterilebilir:

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