Đoạn code dưới đây sẽ tạo mới slide, dòng title theo chỉ định, ô textbox theo chỉ định.
Kết quả:
Mã:
Sub creat_TxtBox()
Dim pp As PowerPoint.Application, pptdoc As Slide, pptLayout As CustomLayout
Set pp = CreateObject("PowerPoint.Application")
pp.Visible = True
'If you are creating a new Presentation and New slide the
pp.Presentations.Add
Set pptLayout = pp.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)
Set pptdoc = pp.ActivePresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
'Title
pptdoc.Shapes.Title.TextFrame.TextRange.Text = "tuhocvba"
Set sldTitle = pptdoc.Shapes.Title
With sldTitle
With .TextFrame.TextRange
With .Font
.Bold = msoTrue
.Size = 32
.Color = RGB(0, 0, 200)
End With
End With
End With
sldTitle.Top = 10
'If you are using an existing presentation then delete above 3 lines use the 2 lines below
'pp.Presentations.Open ("C:\users\User\desktop\test.pptm")
'Set pptdoc = pp.ActivePresentation.Slides(1)
Set Sh = pptdoc.Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=150, Height:=60)
Sh.TextFrame.TextRange.Text = "TuhocVBA"
Sh.TextFrame.TextRange.Font.Color = RGB(255, 100, 255)
'them
'Create shape with Specified Dimensions and Slide Position
Set Shp = pptdoc.Shapes.AddShape(Type:=msoShapeRectangle, _
Left:=24, Top:=65.6, Width:=672, Height:=26.6)
'FORMAT SHAPE
'Shape Name
Shp.Name = "My Header"
'No Shape Border
Shp.Line.Visible = msoTrue 'msoFalse
'Shape Fill Color
Shp.Fill.ForeColor.RGB = RGB(184, 59, 29)
'Shape Text Color
Shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
'Text inside Shape
Shp.TextFrame.TextRange.Characters.Text = "[Header]"
'Center Align Text
Shp.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
'Vertically Align Text to Middle
Shp.TextFrame2.VerticalAnchor = msoAnchorMiddle
'Adjust Font Size
Shp.TextFrame2.TextRange.Font.Size = 14
'Adjust Font Style
Shp.TextFrame2.TextRange.Font.Name = "Arial"
End Sub
Bạn cần đăng nhập để thấy hình ảnh